Skip to Content
0

Bind Single Value from OData to SAPUI5 Element "sap.ui.commons.TextField"

Apr 03, 2017 at 06:48 AM

81

avatar image

Hello and sorry if this long winded - just want to put all the information needed to assist getting the answer.

The following links did not help me:
https://archive.sap.com/discussions/thread/3406353
https://archive.sap.com/discussions/thread/3779809

In SAP (SEGW), I have an OData Project called ZMM_GWS_PO.
I have an Entity Type called PO_Line_Items.
I have an Entity Set called PO_Line_Items_ES.
I have several properties in Entity Type PO_Line_Items, of which I just want to retrieve EBELN and put it into a UI Element in ZPO.view.js.
I have redefined Method PO_LINE_ITEMS_ES_GET_ENTITYSET, of which I can successfully retrieve an entire table of data.
I thought perhaps I needed to redefine Method PO_LINE_ITEMS_ES_GET_ENTITY.

In ZPO.view.js I have:
var L_EBELN = new sap.ui.commons.TextField( "l_ebeln", { width: '10px', maxLength: 10 } );

I want UI Element L_EBELN to be a value retrieved from Entity Type PO_Line_Items's Property EBELN.

So how to do it??

The following 5 things individually did not work and nothing happens when they are executed - I get a blank page:

l_ebeln.bindElement( "/PO_Line_Items_ES('4500000000')/EBELN" );
l_ebeln.bindElement( "/PO_Line_Items('4500000000')/EBELN" );
l_ebeln.bindProperty( "value", "/PO_Line_Items_ES('4500000000')" );
l_ebeln.bindProperty( "value", "/PO_Line_Items('4500000000')" );

var sRead = "/PO_Line_Items_ES(EBELN='4500000000')";
l_odata_model.read( sRead, null, null, true, 
  function(oData, oResponse) {
    l_ebeln.setValue( oData.EBELN );
  }, function() {
    alert("Read Failed");
  } 
);

(I have successfully done Table binding, so that's not what I need to do here - I know how to do that!)
What is the syntax for ONE VALUE in my ODATA to go into ONE UI Element in my View?

A code snippet is best to show me what I'm doing wrong.

Thanks in advance,

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

1 Answer

Best Answer
Sean Machado Apr 06, 2017 at 05:01 AM
0

To anyone who might find this useful, I have found the answer, though surprised it didn't come from a response here.

var l_odata_model = sap.ui.getCore().getModel();  //From the Controller onInit Function
var L_EBELN = new sap.ui.commons.TextField( "l_ebeln", { width: '100px', maxLength: 10 } );

l_ebeln.setModel( l_odata_model );                                              //Connection to SAP OData Project
l_ebeln.bindElement( "/PO_Line_Items_ES(EBELN='4500000000',EBELP='000010')" );  //Entity Set and its Keys
l_ebeln.bindValue( "EBELN" );                                                   //The Field in my Entity I want
Share
10 |10000 characters needed characters left characters exceeded