Page 1 of 1
Getting list from OData via variable list
Posted: Wed May 01, 2024 7:49 am
by fiorent
Hello,
I am preparing a report consisting of lists. The data in the list is selected by the user. So the data varies from user to user.
All data is stored in the OData database. How can I get relevant data from user with OData script?
For example, I was able to get data with a script. I just defined a variable to get some data (type is integer value). Scenario:
ODataSalesDocumentMaterials?$filter=(Id eq {contractid})
But I need all the data selected by the user. So how can I get these?
Re: Getting list from OData via variable list
Posted: Wed May 01, 2024 9:33 am
by Lech Kulikowski
Hello,
You can use the Request From User option for your variable.
Thank you.
Re: Getting list from OData via variable list
Posted: Thu May 02, 2024 12:20 pm
by hbasaraner
Hello. I have a similar issue too. In my NextJS project I'm sending parameters like this array of object:
Code: Select all
[{key: "idList", value: [1001, 1002, 1003]}]
After initializing ReportJS, I set parameters to variables like this:
Code: Select all
parameters?.forEach((parameter: any) => {
const variable = report.dictionary.variables.getByName(parameter.key);
if (variable) {
variable.valueObject = parameter.value;
}
});
I set my variable type integer list on Stimulsoft ReportJS. But I can't iterate to filter data. Here is my scenario:
Code: Select all
OData_UsersTable?$filter=(Id in ({idList})
I assume that Stimulsoft reads my variable like:
Code: Select all
OData_UsersTable?$filter=(Id in ([1001, 1002, 1003])
Is there a way to loop array to query like this?:
Code: Select all
OData_UsersTable?$filter=(Id in (1001, 1002, 1003)
Re: Getting list from OData via variable list
Posted: Thu May 02, 2024 5:00 pm
by Lech Kulikowski
Hello,
In this case, you should the ToQueryString() function for your variable:
{idList.ToQueryString()}
Thank you.
Re: Getting list from OData via variable list
Posted: Thu May 02, 2024 6:12 pm
by hbasaraner
Lech Kulikowski wrote: ↑Thu May 02, 2024 5:00 pm
Hello,
In this case, you should the ToQueryString() function for your variable:
{idList.ToQueryString()}
Thank you.
I tried this approach but it didn't solve my problem. It returns "400: Bad Request". Might be there another issue? Am I doing wrong in NextJS to set variable? Can you check this:
Code: Select all
parameters?.forEach((parameter: any) => {
const variable = report.dictionary.variables.getByName(parameter.key);
if (variable) {
variable.valueObject = parameter.value;
}
});
Re: Getting list from OData via variable list
Posted: Thu May 02, 2024 7:46 pm
by Lech Kulikowski
Hello,
Please check the following code for the List variable:
Code: Select all
var newVariable = new Stimulsoft.Report.Dictionary.StiVariable();
newVariable.name = "Variable";
newVariable.alias = "Variable";
newVariable.type = Stimulsoft.System.StimulsoftStringList;
newVariable.requestFromUser = true;
var di = new Stimulsoft.Report.Dictionary.StiDialogInfo();
di.allowUserValues = false;
di.keys = ["1", "2", "3", "4"];
di.values = ["1", "2", "3", "4"];
newVariable.dialogInfo = di;
Thank you.
Re: Getting list from OData via variable list
Posted: Fri May 03, 2024 12:51 pm
by hbasaraner
Lech Kulikowski wrote: ↑Thu May 02, 2024 7:46 pm
Hello,
Please check the following code for the List variable:
Code: Select all
var newVariable = new Stimulsoft.Report.Dictionary.StiVariable();
newVariable.name = "Variable";
newVariable.alias = "Variable";
newVariable.type = Stimulsoft.System.StimulsoftStringList;
newVariable.requestFromUser = true;
var di = new Stimulsoft.Report.Dictionary.StiDialogInfo();
di.allowUserValues = false;
di.keys = ["1", "2", "3", "4"];
di.values = ["1", "2", "3", "4"];
newVariable.dialogInfo = di;
Thank you.
I tried this method too, but no chance. I set the query as below from edit menu. It returns data when I click Run button, but I can't pass the value from my UI.
Code: Select all
OData_UsersTable?$filter=Id in ({idList.ToQueryString()})
When I check request from network it sends OData URL parameters like:
I don't understand where the issue is happening.
Also, here is my variable settings if it's helpful:

Re: Getting list from OData via variable list
Posted: Mon May 06, 2024 8:40 pm
by Lech Kulikowski
Hello,
Please provide more detailed information on how you load and run reports, how do you send parameters for the report, etc.
Thank you.