OData Service

Consume an Odata service in sapui5 application (Read Odata service)


            How to consume an Odata service from sapui5 mobile application is explained here.
Pre-requisites
1.odata service
2.sapui5 library files loaded

      Here we will use OData Model of SAPUI5 framework.The OData model is a server-side model, meaning that the data set is only available on the server and the client only knows the currently visible (requested) data. Operations, such as sorting and filtering, are done on the server. The client sends a request to the server and shows the returned data.

     The OData model currently supports OData version 2.0.SAP reccommend using v2 model.

 Steps
  1. Create model instance.One OData model instance can cover only one OData service.
  2. var oModel = new sap.ui.model.odata.v2.ODataModel({
        serviceUrl: "https://cors-anywhere.herokuapp.com/services.odata.org/V2/Northwind/Northwind.svc/",
        /*headers: {
            "myHeader1" : "value1",
            "myHeader2" : "value2"
        }*/
    });
    
    
  3.  Read entity.This triggers a get request to the specified path.
  4. oModel.read("/Categories", {
        method: "GET",
        success: function(data) {
            alert(JSON.stringify(data));
        },
        error: function() {
    
        }
    });
    
  5. See Sample provided.Here on clicking the button OData read operation is performed.

  6. OData Read Operation
If you enjoyed this post, Please Share!!

5 comments :

  1. You are lifesaver ;) thanks a lot.

    ReplyDelete
    Replies
    1. Thanks for your valuable feedback

      Delete
  2. Hi Rajeesh,

    Can you provide something similar for triggering an update function from SAPUI5 to SAP?

    ReplyDelete

Powered by Blogger.