Skip to Content

$count automatically atteched to Request URLS in SAPUi5

Jul 21, 2017 at 11:49 AM


avatar image

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 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");


// 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:


// Reponse

<?xml version="1.0" encoding="utf-8" standalone="yes"?><error xmlns=""><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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Srikanth KV 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
Show 2 Share
10 |10000 characters needed characters left characters exceeded

Thanks Srikanth,

Though i'm not using manifest.json, your answer sent me looking further into the ODataModel constructor and its parameters

i could solve my issue with:



"dataSources": {

"mainService": {

"uri": "$format=json",

"type": "JSON"


How do I read in JSON type (JSONModel)

example in ODataModel:

this.getModel().read("/d/results/$count", {

success: function (oData) {

oViewModel.setProperty("/countAll", oData);



Sharath M G 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.



Show 2 Share
10 |10000 characters needed characters left characters exceeded

Hi Sharath,

please could you be more specific?

what do you by

"Try to test your oData URI by attaching the count in your gateway - service test". How can this be done?

I'm using .xsodata Framework(i.e on SAP HANA) and testing the URIs with Postman and so far i know $count=<value> is not a valid Odata request



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.