Getting list from OData via variable list

Stimulsoft PDF Forms discussion
Post Reply
fiorent
Posts: 3
Joined: Wed May 01, 2024 5:34 am

Getting list from OData via variable list

Post 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?
Lech Kulikowski
Posts: 6538
Joined: Tue Mar 20, 2018 5:34 am

Re: Getting list from OData via variable list

Post by Lech Kulikowski »

Hello,

You can use the Request From User option for your variable.

Thank you.
hbasaraner
Posts: 4
Joined: Tue Apr 30, 2024 5:24 am

Re: Getting list from OData via variable list

Post 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)
Lech Kulikowski
Posts: 6538
Joined: Tue Mar 20, 2018 5:34 am

Re: Getting list from OData via variable list

Post by Lech Kulikowski »

Hello,

In this case, you should the ToQueryString() function for your variable:
{idList.ToQueryString()}

Thank you.
hbasaraner
Posts: 4
Joined: Tue Apr 30, 2024 5:24 am

Re: Getting list from OData via variable list

Post 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;
          }
        });
Lech Kulikowski
Posts: 6538
Joined: Tue Mar 20, 2018 5:34 am

Re: Getting list from OData via variable list

Post 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.
hbasaraner
Posts: 4
Joined: Tue Apr 30, 2024 5:24 am

Re: Getting list from OData via variable list

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

Code: Select all

$filter: Id in ()
I don't understand where the issue is happening.

Also, here is my variable settings if it's helpful:
Image
Attachments
Screenshot 2024-05-03 at 15.37.25.png
Screenshot 2024-05-03 at 15.37.25.png (25.99 KiB) Viewed 3041 times
Lech Kulikowski
Posts: 6538
Joined: Tue Mar 20, 2018 5:34 am

Re: Getting list from OData via variable list

Post 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.
Post Reply