SAP UI5 Get OData EntitySet Code Snippets

SAP UI5 Get OData EntitySet Code Snippets

 

Metnod 1:

 

dynamicBindingRegionData: function(evt) {

    var oViewModel = evt.getView().getModel(“ZCustomizing”);

    var oDataJson = oViewModel.getData();

 

    if (evt.selectedKeyCountry === “”){

        oDataJson.RegionCustomizing = [];

        oViewModel.setData(oDataJson);

        return;

    }

 

    var sfilter = “countryID eq ‘” + evt.selectedKeyCountry + “‘”;

    var sPath = “/CustomizingRegionCollection?$filter=” + jQuery.sap.encodeURL(sfilter);

    this.oDataModel.read(sPath,

        null, null, false,

        function(oData, oResponse) {

            oDataJson.RegionCustomizing = oData.results;

            oViewModel.setData(oDataJson);

            // this.getView().setModel(oViewModel, “json”);                   

        },

 

        function(oError) {});

 

}    

 

 

Method 2:

  1. Define JS file and function.

 

sendBatchReadRequests: function(oModel, aRequestURLs, callbackSuccess, callbackError){

    var aBatchOperation = [];

    for(var i in aRequestURLs){

        var oReadOp = oModel.createBatchOperation(aRequestURLs[i], “GET”);

        aBatchOperation.push(oReadOp);

    }

    cus.crm.mycontacts.CRM_MYCONTExtension.util.Util.sendBatchReadOperations(oModel, aBatchOperation, callbackSuccess, callbackError);

}

 

  1. Read OData EntitySet and Populate the Data to Custom JSONModel in Control JS

 

/* MODIFICATION BEGIN Wei.Zhu 2017.09.12

Adjustment MyAccount Filter button adn Create Button

*/

 

onInit: function() {

    var constants = new sap.ui.model.json.JSONModel(cus.crm.myaccounts.util.Constants);

    this.getView().setModel(constants, “constants”);    

    if(!this.oDataModel)

        this.oDataModel = this.getView().getModel();

        

    //-> MODIFICATION BEGIN Wei.Zhu 2017.09.22 Set Customizing Extension Data

    this.ZcustomizingModel = new sap.ui.model.json.JSONModel({SalesOrganizationCustomizing: []});

    this.getView().setModel(this.ZcustomizingModel, “ZCustomizing”);

    this._ZreadCustomizing();    

    //<- MODIFICATION END    

},

 

 

 

_ZreadCustomizing: function(callbackCustomizingRead) {

    var that = this;

    cus.crm.myaccounts.util.Util.sendBatchReadRequests(

            this.oDataModel,

            [“CustomizingSalesOrganizationCollection”],

            function(oResponses) {

                var aSalesOrganizations = oResponses[“CustomizingSalesOrganizationCollection”];

                aSalesOrganizations.unshift({SalesOrg:””, SalesOrgText:””});

                that.ZcustomizingModel.setProperty(“/SalesOrganizationCustomizing”, aSalesOrganizations);

        

                if (callbackCustomizingRead)

                    callbackCustomizingRead.call(that);

            }

    );

}

 

 

    

Leave a Comment