Skip to Content
0

SAPUI5 Get entityset data to a variable

Sep 03, 2017 at 05:11 PM

531

avatar image
Former Member

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.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
avatar image
Former Member Sep 03, 2017 at 09:15 PM
0

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");} });
Share
10 |10000 characters needed characters left characters exceeded
Ravi kiran R Sep 04, 2017 at 07:44 AM
0

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

Share
10 |10000 characters needed characters left characters exceeded
Sergio Guerrero Sep 03, 2017 at 05:40 PM
0

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

Show 3 Share
10 |10000 characters needed characters left characters exceeded
Former Member

sorry for this typo. but still no data retrieved

0

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

0
Former Member

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

0