cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieving entity data via OData Model

Former Member
0 Kudos

Hello,

Since I'm an absolute beginner in javascript and SAP UI5 I think this question can be answered easily.

I'm developing an extension for the SAP ESPM Scenario and I have a problem with consuming the OData Service:

To test whether I retrieve any Data from the ABAP backend-system, I'm trying to write data into a textarea-control.

I tried first with the read-method:

var fnSuccess = $.proxy(function() {

            console.log("success");

        }, this);

        var fnError = $.proxy(function() {

            console.log("error");

        }, this);

        var oValue = sap.app.odatamodel.read("/Products('HT-1000')?$select=Name", null, null, true, fnSuccess, fnError);

        var oText = new sap.ui.commons.TextArea({

            value : oValue,

            visible : true,

            width : "100%"

        });

I got [objekt] objekt as a return in my textarea.

Then I tried the bind-method:

var oText = new sap.ui.commons.TextArea({

            value : "",

            visible : true,

            width : "100%"

        });

        oText.bindElement("/Products('HT-1000')?$select=Name", {

            select : "Name"

        });

Here I get the following error:

Methode 'PRODUCTS_GET_ENTITY' in Datenanbieterklasse nicht implementiert.

I'm not sure, but does that mean that the get-entity-method is locked or something like that? Won't I ever be able to directly address one entity?

Thanks for your help!

Daniel

Accepted Solutions (1)

Accepted Solutions (1)

former_member91307
Contributor
0 Kudos

Hi Daniel,

Return statement of odatamodel.read is  an object which has an abort function to abort the current request. as mentioned below

https://sapui5.netweaver.ondemand.com/sdk/#docs/api/symbols/sap.ui.model.odata.ODataModel.html#read

so oValue would contain an object which is displayed as [objekt] objekt

the read value is passed with the function success call so the above code could be changed as below

var fnSuccess = $.proxy(function(data) {

            console.log("success");

          oText.setValue(data.Name)

        }, this);

        var fnError = $.proxy(function() {

            console.log("error");

        }, this);

        var oValue = sap.app.odatamodel.read("/Products('HT-1000')?$select=Name", null, null, true, fnSuccess, fnError);

        var oText = new sap.ui.commons.TextArea({

            value : oValue,

            visible : true,

            width : "100%"

        });

For bind method to work change code as below

var oText = new sap.ui.commons.TextArea({

            value : "{Name}",

            visible : true,

            width : "100%"

        });

        oText.bindElement("/Products('HT-1000')", {

            select : "Name"

        });

Thanks and Regards, Venkatesh

Answers (2)

Answers (2)

Former Member
0 Kudos

Thanks to both of you.

@Venkatesh : Unfortunately both versions didn't work. Is it posible to use the variable Name via data.Name in this context?

@Krishna : I guess you mean that I'll have to change the server configuration, but I have no idea where and how. But since I can address one entity like this in my browser: /Products$filter=ProductId%20eq%20'HT-1000'&$select=Name , isn't it possible to use the same URI for a method call like I did it with the read-method?

Thanks again,

Daniel

former_member91307
Contributor
0 Kudos

Hi Daniel,

Please log 'data' in console to see the format received

add following statement

var fnSuccess = $.proxy(function(data) {

console.log(data);

Thanks and Regards, Venkatesh

kammaje_cis
Active Contributor
0 Kudos

Daniel,

The URI you mentioned is of "query with filter" not "read". So I see that query has been implemented in your service, but not the read. Whereas in the UI5 code you are invoking a read.

Here is the code to invoke a query with filter and select.

               oFilter =new sap.ui.model.Filter("ProductId", sap.ui.model.FilterOperator.EQ, "HT-1000") ;


        oText.bindElement("/Products", {

            filters: [oFilter],

            select : "Name"

        });

Thanks

Krishna

kammaje_cis
Active Contributor
0 Kudos

Hi Daniel,

As I see this is problem with the OData service. In the code you are trying to read a specific entry. The error message says that the read functionality is not implemented for the entity Product.

So you need to look at SEGW.

Thanks

Krishna