Skip to Content

SAPUI5 Get entityset data to a variable

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Sep 03, 2017 at 09:15 PM

    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");} });
    Add comment
    10|10000 characters needed characters exceeded

  • Sep 04, 2017 at 07:44 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 03, 2017 at 05:40 PM

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

    Add comment
    10|10000 characters needed characters exceeded