cancel
Showing results for 
Search instead for 
Did you mean: 

How dynamically get property values from entity set

rupeshpandit1999
Explorer
0 Kudos

Hi experts,

I am working on MDK, where I am trying to dynamically get the values from entity set. I am trying to get value from a entity set and push property value in a array dynamically in object. is there any way I can get the value dynamically without using property name with dot (.) operator.

any index based method which I can using get value from item.

Thanks in advance.

Regards,

Rupesh.

Accepted Solutions (0)

Answers (1)

Answers (1)

mingkho
Advisor
Advisor
0 Kudos

Hi Rupert

If my understanding of what you meant is correct, then yes, you can. You can access them like any JavaScript Object (item is an JS Object)

e.g.

context.read("/SAPAssetManager/Services/AssetManager.service","Suppliers",[]).then((result)=>{
        for (var i = 0; i < result.length; i++){
            let item = result.getItem(i);
            for(var prop in item) {
                console.log(prop) // This will print "Property1", "Property2","Property3", and any other properties of that object
                console.log(item[prop]); // This will print each of the value of the property
            }
        }
    });

However, if you what you are looking for is just to convert the ObservableArray to a normal JSON array, you can simply call toJSON method of the result e.g.

let data = result.toJSON();

Regards

Ming