Skip to Content
avatar image
Former Member

$count automatically atteched to Request URLS in SAPUi5

Hello Experts,

Please help me out.

I'm learning UI development with SAPUI5 and trying to query Odata service from Backend without any explicit GET requests e.g oModel.read(...). I have set the Model in Component.js and use Data binding in various xml views. So at runtime SAPUI5 generates the requests but adds the $count parameter to every reqest url. Ultimately this results in a 400 - Bad Request response(although in most cases the correct data is returned). I 'd like to know if this a normal SAPUI5 behaviour or if its an Issue related to my code and how it can be resolved.

//model in Component.js


var url = "http://<host>/<serviceNameSpace>/myService.xsodata/";

var oModel = new sap.ui.model.odata.ODataModel(url, true, "user", "pswd");

oView.setModel(oModel);

// Some Bindings in XmlViews
<List id="locs" items="{path: '/LOCATIONS?$expand=Rooms'}" >

<List id="list" items="{/ROOMS?$expand=State,D_AGG}">

//Generated GET-Request URLS:
http://<host>/<serviceNameSpace>/myService.xsodata/LOCATIONS?$expand=Rooms/$count

http://<host>/<serviceNameSpace>/myService.xsodata/ROOMS?$expand=State,D_AGG/$count

// Reponse

<?xml version="1.0" encoding="utf-8" standalone="yes"?><error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><code/><message xml:lang="en-US">Syntax error in $expand system query option at position '12': entityNavProperty '$count' is not a valid navigation property for type 'myService.ROOMSType'.</message></error>

i'd appreciate any Pointers

Thanks in advance

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Jul 24, 2017 at 09:56 PM

    By default when OData model is created using manifest.json every request is attached with $count.

    To remove $count edit manifest.json file where the model is defined(its under sap.ui5 --> models ).

    check the below code for manifest.json assuming your model name is 'myService'

    "sap.ui5": {
         "models": {
             "myService": {
                  "dataSource": <My Service Datasource URL>,
                  "type": "sap.ui.model.odata.v2.ODataModel",
                  "settings": {
                       "defaultCountMode": "None"       //this disables $count on all requests
                  }
              }
         }
    }
    Add comment
    10|10000 characters needed characters exceeded

  • Jul 21, 2017 at 02:52 PM

    Since you are using a list, the framework automatically attaches $count to limit the no. of records retrieved by the entity.

    Try to test your oData URI by attaching the count in your gateway - service test and confirm if you are getting the data i.e. attach $count=200 to the URI int he gateway and confirm the response. If its working in backend gateway then you can look at it from the frontend.

    Regards,

    Sharath

    Add comment
    10|10000 characters needed characters exceeded

    • Gateway service builder has the option to test the oData service.

      To avoid the framework appending the $count, do not use the entity mapping in the XML. Try to manually bind the entity to the view control in the controller. This way, you avoid the appending of $count filter to URI.

      Regards,

      Sharath