I have developed the ODATA service based on RFC which has some assoication betwen Entity's and used $expand option to retrieve all the releavant data. When i use the following uri to test in Gateway client. I am able to get the data as expected.
/sap/opu/odata/sap/Z_EXP_TEST_SRV/EntitySet1('userid')/?$format=json&$expand=NavEntity2,NavEntity3,NavEntity4,NavEntity5
But When i tried to use this service from SAP UI5 using the following code, i am able to see only the results of EntitySet1 as part of the response json. I am not able to see the data related to EntitySet2,En,EntitySet3,EntitySet4, EntitySet5
Please let me know how to call or initialize this service from UI5 for getting results of all the EntitySets using the $expand option. Here is the sample code i am written to intialize the ODATA service to read the results of all the entity's in one call.
this._oGLValueHelpSvcOdataModel = new sap.ui.model.odata.v2.ODataModel({
serviceUrl: "/sap/opu/odata/sap/Z_EXP_TEST_SRV/", json: true, loadMetadataAsync: true,
headers: {
"Accept" : "application/json",
"Cache-Control" : "NO-CACHE"
}
}).attachMetadataFailed(function(oControlEvent) {
that._oLogger.error("There was an error loading Service metadata. The error is:Response:"+JSON.stringify(oControlEvent.getParameter("response")));
}).attachMetadataLoaded(function(oControlEvent) {
//that._oLogger.info("OData service metadata is loaded successfully.");
that._oGLValueHelpSvcOdataModel.read("/EntitySet1('"+loggedUser+"')/? $format=json&$expand=NavEntity2,NavEntity3,NavEntity4,NavE ntity5", {
success: function (oData) {
that.getView().getModel("userDataModel").setData(oData);
console.log("oResourcePlanModel--->:"+that.getView().getModel("userDataModel").getJSON());
},
error: function (error) {
console.log("Erros getting User Data. Error is:"+error);
//that._oMessageManager.removeAllMessages();
//that._oLogger.error("Erros getting User Data. Error is:"+error);
}
});
});
Here is the output: I able to get the only EntitySet1 values in response,but all rest of the entity's are empty. when i run from SAPUI5
{"__metadata":{"id":"https://System.com/sap/opu/odata/sap/Z_EXP_TEST_SRV/EntitySet1('TestUser')","uri":"https://System.com/sap/opu/odata/sap/Z_EXP_TEST_SRV/EntitySet1('TestUser')","type":"Z_EXP_TEST_SRV.UserData"},"Bname":"TestUser","ZJobCode":"400161","ZCenter":"2540002","ZfglLgcycntr":"2540002","Prctr":"0000012426","ZErrorMsg":"","NavEntity2":{"__deferred":{"uri":"https://System.com/sap/opu/odata/sap/Z_EXP_TEST_SRV/UserDataSet('TestUser')/NavEntity2"}},"NavEntity3":{"__deferred":{"uri":"https://System.com/sap/opu/odata/sap/Z_EXP_TEST_SRV/UserDataSet('TestUser')/NavEntity3"}},"NavEntity4":{"__deferred":{"uri":"https://System.com/sap/opu/odata/sap/Z_EXP_TEST_SRV/UserDataSet('TestUser')/NavEntity4"}},"NavEntity5":{"__deferred":{"uri":"https://System.com/sap/opu/odata/sap/Z_EXP_TEST_SRV/UserDataSet('TestUser')/NavEnity5"}}}