cancel
Showing results for 
Search instead for 
Did you mean: 

how to trigger GET_ENTITY class from sap ui5?

former_member182645
Participant
0 Kudos

hi  all

we write some code in odata service... and

GET_ENTITY class execute successfully...

which returns only singal value.

but when try to trigger service from sap ui5 ---> its goes directly to GET_ENTITYSET.

how to execute GET_ENTITY?

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member196593
Participant
0 Kudos

Hi Radhes

Pls see the sample code bellow rewards point its helpfull.

oModelJson = new sap.ui.model.json.JSONModel();

  oModel.read("/EntitySetname('"+oId+"')",null,null,true,function(oDataDialogNew,oResponse){

  oModelJson.setData(oDataDialogNew,"oDataDialogNew");

former_member182645
Participant
0 Kudos

thanks for reply

this is component.js

confused to where set parameters..

sap.ui.core.UIComponent.extend("ztrycount.Component", {

    metadata : {

        "name" : "zdocount",

        "version" : "1.1.0-SNAPSHOT",

        "library" : "ztrycount",

        "includes" : [ "css/fullScreenStyles.css" ],

        "dependencies" : {

            "libs" : [ "sap.m", "sap.ui.layout" ],

            "components" : []

        },

  "config" : {

  resourceBundle : "i18n/messageBundle.properties",

  serviceConfig : {

  name: "ZCOUNT_SRV",

  serviceUrl: "/sap/opu/odata/sap/ZCOUNT_SRV/"

  }

  },

        routing : {

            // The default values for routes

            config : {

                "viewType" : "XML",

                "viewPath" : "ztrycount.view",

                "targetControl" : "fioriContent", // This is the control in which new views are placed

                "targetAggregation" : "pages", // This is the aggregation in which the new views will be placed

                "clearTarget" : false

            },

  routes : [

  {

  pattern : "",

  name : "main",

  view : "Master"

  },

  {

  name : "details",

  view : "Details",

  pattern : "{entity}"

  }

  ]

        }

    },

    /**

     * Initialize the application

     *

     * @returns {sap.ui.core.Control} the content

     */

    createContent : function() {

        var oViewData = {

            component : this

        };

        return sap.ui.view({

            viewName : "ztrycount.view.Main",

            type : sap.ui.core.mvc.ViewType.XML,

            viewData : oViewData

        });

    },

    init : function() {

        // call super init (will call function "create content")

        debugger;

        sap.ui.core.UIComponent.prototype.init.apply(this, arguments);

        // always use absolute paths relative to our own component

        // (relative paths will fail if running in the Fiori Launchpad)

        var sRootPath = jQuery.sap.getModulePath("ztrycount");

        // The service URL for the oData model

        var oServiceConfig = this.getMetadata().getConfig().serviceConfig;

        var sServiceUrl = oServiceConfig.serviceUrl;

        // the metadata is read to get the location of the i18n language files later

        var mConfig = this.getMetadata().getConfig();

        this._routeMatchedHandler = new sap.m.routing.RouteMatchedHandler(this.getRouter(), this._bRouterCloseDialogs);

        // create oData model

        this._initODataModel(sServiceUrl);

   

        // set i18n model

        var i18nModel = new sap.ui.model.resource.ResourceModel({

            bundleUrl : [ sRootPath, mConfig.resourceBundle ].join("/")

        });

        this.setModel(i18nModel, "i18n");

        // initialize router and navigate to the first page

        this.getRouter().initialize();

    },

    exit : function() {

        this._routeMatchedHandler.destroy();

    },

    // This method lets the app can decide if a navigation closes all open dialogs

    setRouterSetCloseDialogs : function(bCloseDialogs) {

        this._bRouterCloseDialogs = bCloseDialogs;

        if (this._routeMatchedHandler) {

            this._routeMatchedHandler.setCloseDialogs(bCloseDialogs);

        }

    },

    // creation and setup of the oData model

    _initODataModel : function(sServiceUrl) {

        jQuery.sap.require("ztrycount.util.messages");

        var oConfig = {

            metadataUrlParams : {},

            json : true,

            // loadMetadataAsync : true,

            defaultBindingMode :"TwoWay",

            defaultCountMode: "Inline",

            useBatch : true

        };

        var oModel = new sap.ui.model.odata.v2.ODataModel(sServiceUrl, oConfig);

        oModel.attachRequestFailed(null, ztrycount.util.messages.showErrorMessage);

        this.setModel(oModel);

    }

frankluzat
Participant
0 Kudos

Hi Radhesh,

according to your routing configuration your are passed the parameter "Entity" for your details view.

In your detail view controller's onRouteMatched method you take this parameter and set the view's binding context accordingly. Either you pass a simple value and build the URL for the OData GetEntity yourself [e.g. YourEntitySet(KeyField1='keyvalue1',KeyField2='keyvalue2') ] or your pass the binding path with this parameter.

Please refer to this documentation (the "Controller" section) to have a best practive approach.

Step 9: Detail View - UI Development Toolkit for HTML5 (SAPUI5) - SAP Library

If you set a binding context using the YourEntitySet( [specify all key fields with values here] ) notation the the GetEntity Method will be called in NW Gateway.

kedarT
Active Contributor
0 Kudos

Hi Radhesh.

You need to put in parameters to your odata call to hit GET_ENTITY, something like below:

oModel.createBindingContext("/Path(par1='" + filter1 + "',par2='" + Filter2)

Hope this helps.

former_member182645
Participant
0 Kudos

Hi @Kedar Tingikar

what is path in it?