cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5 Get entityset data to a variable

Ibrahem
Participant
0 Kudos
12,158

Dears,

I want to get entity set data to a variable using class "sap.ui.model.odata.v2.ODataModel" but always the variable value is undefined.

as I read OData v2 is loading data async but till now I don't have any clue how to load data into a variable.

//Creating the Model Instance
// "/destination/ODataTest" is defiended in my neo-app.json"
var oModel = new sap.ui.model.odata.v2.ODataModel("/destination/ODataTest/Northwind/Northwind.svc/");

var DataLoaded = oModel.read("/Products",
{success: function(){
    MessageToast.show("Success");
}, error: function(e){
    MessageToast.show("Failed");}
});

Thank you.

Accepted Solutions (1)

Accepted Solutions (1)

Ibrahem
Participant

For sharing, I found a solution by reading SAP standard app after importing it from ABAP repository to web IDE

var DataLoaded = oModel.read("/Products",
	{success: function(response){
//response will have the retrun of the request console.log(response.results); MessageToast.show("Success"); }, error: function(e){ MessageToast.show("Failed");} });

Answers (2)

Answers (2)

former_member192494
Participant
0 Kudos

Hi,

You could use the below method to see if metadata is loaded, post which you can check if the data is getting binded to your controls.

oDataModel.attachMetadataLoaded(function(){

var oMetadata = oDataModel.getServiceMetadata();

});

Regards,

Ravikiran

SergioG_TX
Active Contributor
0 Kudos

looks like your destination url is missing " right after the ( on the new model creation

Ibrahem
Participant
0 Kudos

sorry for this typo. but still no data retrieved

SergioG_TX
Active Contributor
0 Kudos

does the destination exist? you may be facing an issue where your destination is not correct.

IF this destination is not local (since you are using a relative path) try to use the destination with a fully qualified path and then try again

Ibrahem
Participant
0 Kudos

the metadata file is loaded successfully. so I believe -correct me if I'm wrong- there is no issue with distination