1

I need to pass dynamic valued input parameter to calculation view via Odata binding to grid table. I can get calculation view result from Odata with following syntax:

...odata/SERVICE.xsodata/DataSetParameters(P_END_DATE=datetime'2013/07/10',P_START_DATE=datetime'2013/07/03')/Results?$format=json

I am binding grid table with following code in controller (date will be dynamic in actual application)

var gridTable = _this.getView().byId(gridName);
gridTable.setModel(oModel);
gridTable.bindRows("DataSet(P_END_DATE=datetime\'2013/07/10\',P_START_DATE=datetime\'2013/07/03\')", null, null, aFilters);

In runtime I am getting following errors

No key property 'P_END_DATE' exists in type...No key property 'P_END_DATE' exists in type ...Collection 'DataSet' is not directly accessible....Collection 'DataSet' is not directly accessible.

Can anyone help me to know what is the correct syntax to pass the parameter from odata binding?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Suman Biswas
  • 169
  • 3
  • 7
  • 20

1 Answers1

1

The ODATA collection you expose will be available at /Results and is not directly accessible with /DataSet.

A NavigationProperty is required to retrieve the results from the parameterized call. So you will have to change your binding path to this

DataSetParameters(param1=value,param2=value)/Results

Controller code gridTable.bindRows("DataSetParameters(P_END_DATE=datetime\'2013/07/10\',P_START_DATE=datetime\'2013/07/03\')/Results", null, null, aFilters);

Stephen S
  • 3,936
  • 2
  • 23
  • 33
  • Now oData url can build correctly and data is retrieving (checked in Chrome console) but data is not showing in grid table. In console can see the following error `2017-02-24 21:35:12.243000 The following problem occurred: HTTP request failed400,Bad Request,{ "error": { "code": "", "message": { "lang": "en-US", "value": "Collection 'DataSet' is not directly accessible."}}} - ` My grid binding code looks like `gridTable.bindRows("oDataModel>/DataSetParameters(P_END_DATE=datetime\'2013/07/10\',P_START_DATE=datetime\'2013/07/03\')/Results", null, null, aFilters);` – Suman Biswas Feb 24 '17 at 16:09
  • Is oDataModel your data model? if that is so, then you are not binding correctly – Stephen S Feb 24 '17 at 16:19
  • Yes oDataModel is my model name defined in manifest.json. I am following the same syntax for all bindings only difference is there has no parameter. Do I need to set model as table.setModel(oDataModel) and dataset with parameter as you mentioned? – Suman Biswas Feb 24 '17 at 16:24
  • The way you are binding it is incorrect. "oDataModel>/DataSetParameters(......" would work in the XML notation, however for Javascript in you controller it's different – Stephen S Feb 24 '17 at 16:49
  • You will have to do it this way `gridTable.bindRows("/DataSetParameters(P_END_DATE‌​=datetime\'2013/07/1‌​0\',P_START_DATE=dat‌​etime\'2013/07/03\')‌​/Results", null, null, aFilters); gridTable.setModel(oDataModel);` – Stephen S Feb 24 '17 at 16:50
  • If you know the syntax can you please share it with me, really it will be very helpful. For an update now with this syntax I can see data in grid table but still throwing error popup and in console same error as I mentioned earlier. If you have any idea about solution please share it with me. Thank you for your help. – Suman Biswas Feb 24 '17 at 17:02
  • I tried with this as well but `gridTable.setModel(oDataModel);` was before of the line `gridTable.bindRows("/DataSetParameters(P_END_DATE‌​=datetime‌​\'2013/07/1‌​0\',P_S‌​TART_DATE=dat‌​etime‌​\'2013/07/03\')‌​/Re‌​sults", null, null, aFilters); ` but it is not showing data. Practically it is not triggering any batch request in console with this. – Suman Biswas Feb 24 '17 at 17:06
  • I'm afraid you'll have to share more code as to how you initiate the OData model, create and bind the table – Stephen S Feb 24 '17 at 17:15
  • I am defining model in manifest and then assigning at init. and next getting model from view and these codes are as :`var oModel = this.getView().getModel("oDataModel"); gridTable.setModel(oModel);gridTable.bindRows("oDataModel>/DataSetParameters(P_END_DATE‌​=datetime\'2013/07/1‌​0\',P_START_DATE=dat‌​etime\'2013/07/03\')‌​/Results", null, null, aFilters);` about binding these process I am following. – Suman Biswas Feb 24 '17 at 18:24
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/136590/discussion-between-stephen-s-and-suman-biswas). – Stephen S Feb 25 '17 at 05:27
  • For your kind informaiton, your information solved my issue, I was getting two error message but found this is happening due to other reason. So your solution finally clicked the solution. **Thanks a lot for your help.** – Suman Biswas Feb 27 '17 at 08:20