UI5: OData read parameters

Home / Blog / UI5: OData read parameters

This one was fun…  Like I mentioned yesterday, I was calling a separate OData service for my details.  Because the list could be long, I didn’t want to call this service for every item on the list.  Instead I chose to run it on-demand.  The trick was that I needed to be creative in my call of this service.  It had multiple expands, a filter and of course I didn’t want it to display the detail page until the service was complete.  So, here is what I did:

var mParameters = { var mParameters = {
filters: oFilters,
urlParameters: {
“$expand”: “Exp1,Exp2,Exp3…,Expn” },
success: function(oData, oResponse) {
oNotDet.setData(oData);
oView.setBusy(false);
sap.ui.getCore().setModel(oNotDet, “notdet”);
var bReplace = Device.system.phone ? false : true;
that.getRouter().navTo(“object”, {
objectId: oItem.getBindingContext().getProperty(“Qmnum”)
}, bReplace);
},
error: function(oError) {
jQuery.sap.log.info(“Odata Error occured”);
oView.setBusy(false);
}
};
oView.setBusy(true);
oModel.read(“NotHdr”, mParameters);

The big things to notice here:

Populate your filters before adding them to the parameters (this just makes it cleaner)
Enter in your urlParameters
Success function will navigate to the new view.  This makes sure the data has been received before the new view is displayed.  In my case this was required because the fields displayed were dependent on the data of the detail service.
Finally, I set the view to busy before calling the read statement, then the sucess/failure will change the setBusy to false.

Hope this is useful.  Thanks for reading,

As always, thanks for reading and don't forget to check out our SAP Service Management Products at my other company JaveLLin Solutions,
Mike

Leave a Reply

Your email address will not be published. Required fields are marked *