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 a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    Posted on 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 a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 03, 2017 at 05:40 PM
    -1

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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 04, 2017 at 07:44 AM
    -1

    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 a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.