Search code examples
sapui5master-detailsap-gateway

How to call get_entity method


I'm just starting with SAP FIORI app developing.

I created simple oData model for SAP user details, I implemented two methods:

  • get_entityset - receives list of users with personal number and full name
  • get_entity - receives more details of single user (by username).

When I call the service from browser all works fine. How do I call my get_entity method when loading detail page of Master-Detail FIORI app. I used Master-Detail template from WebIDE, but only get_entitset is called and detail screen uses only set data.

How should I define the data binding (in Detail controller I guess)?


Solution

  • Let's assume your Entity is called User and your EntitySet is called Users. We also assume your Entity has one key field of type Edm.String called UserId and another field called FullName of type Edm.String.

    var sPath = "/the/path/to/my/service";
    var oModel = new sap.ui.model.odata.ODataModel(sPath);
    sap.ui.getCore().setModel(oModel);
    var oText = new sap.ui.commons.TextView({
        text: "{FullName}"
    });   
    oText.bindElement("/Users('MyUserId')");  
    oText.placeAt("content");
    

    Since you are binding to "/Products('MyProductId')" your "get_entity" is called. Binding to "/Products" would call "get_entityset". However, a binding to "/Products" is used for tables or lists and usually not for a simple TextView (like the above example). There are many tutorials on the web and you will see that this is not as complicated as you might guess.