Get variable value in runtime before query string data complete

Stimulsoft Reports.JS discussion
r.polyakov
Posts: 11
Joined: Tue Dec 08, 2020 12:46 pm

Get variable value in runtime before query string data complete

Post by r.polyakov »

Hello.
I am trying to get the values of the report variables before sending it to the server. We have variables in the query string of the report that the user enters. Some variables have default values, for the case if the user did not select the data or the query, based on which the list of data for selection is formed, returned an empty result.
Example:
Data Source
u

Code: Select all

select id, name from users where id > 10
Variables
users_pre

Code: Select all

u.id, u.name
users

Code: Select all

IIF(users_pre.Count == 0, 123, users_pre.ToQueryString())
The users_pre variable contains a list of values that are displayed in the interface. The user can select multiple values from the list. Selected values can be retrieved in the event:

Code: Select all

viewer.onInteraction = function (args) {
        if (args.action == 'Variables') {
            variables = args.variables;
        }
    }
But the value of the users variable is not available in this event. If I understood correctly, it has not yet been calculated at this point.
Can you tell in what event I can get the value of this variable? Perhaps I need to override some event?
I found that the value of this variable is calculated in the following method

Code: Select all

B.prototype.invokeConnecting

Code: Select all

d = t.System.Convert.toString(t.Report.Engine.StiParser.StiParser.parseTextValue(m, a))
and then substituted into the query string.
In what event can this value be received before sending a request to the server, to be able to form a query string on the server?
Thanks.
Lech Kulikowski
Posts: 6254
Joined: Tue Mar 20, 2018 5:34 am

Re: Get variable value in runtime before query string data complete

Post by Lech Kulikowski »

Hello,

Please check the onBeginProcessData events of the viewer.

If the issue still present, please provide more detailed information.

Thank you.
r.polyakov
Posts: 11
Joined: Tue Dec 08, 2020 12:46 pm

Re: Get variable value in runtime before query string data complete

Post by r.polyakov »

Lech Kulikowski wrote: Wed Dec 09, 2020 7:36 am Hello,

Please check the onBeginProcessData events of the viewer.

If the issue still present, please provide more detailed information.

Thank you.

Hello, Lech.
I have tried getting the values of the variables in this event.

queryString:

Code: Select all

select id, user_id, price from purchases where user_id in (200) and status = 1 limit 5
Original query string:

Code: Select all

select id, user_id, price
from purchases
where user_id in ({users}) and status = {status}
limit 5
report.dictionary.variables.getByName("users")

Code: Select all

{val: "IIF(users_pre.Count == 0, 100, users_pre.ToQueryString())", parentComponent: null, fullConvert: true, genAddEvent: true, _inherited: false, …}
report.dictionary.variables

Code: Select all

{    
    "list": [
        {
            "_alias": "users",            
            "_dialogInfo": {                
                "_keys": [],
                "_keysColumn": "",               
                "_values": [],
                "_valuesBinding": [],
                "_valuesColumn": ""
            },            
            "_name": "users",            
            "val": "IIF(users_pre.Count == 0, 100, users_pre.ToQueryString())"
        },
        {
            "_alias": "users_pre",            
            "_dialogInfo": {               
                "_keys": [
                    "100",
                    "200"
                ],
                "_keysColumn": "u1.id",                
                "_values": [
                    "Пользователь 1",
                    "Пользователь 2"
                ],
                "_valuesBinding": [
                    null,
                    null
                ],
                "_valuesColumn": "u1.name"
            },
            "_inherited": false,            
            "_name": "users_pre",            
            "val": ""
        },
        {
            "_alias": "status",            
            "_dialogInfo": {                
                "_keys": [],
                "_keysColumn": "",               
                "_values": [],
                "_valuesBinding": [],
                "_valuesColumn": ""
            },            
            "_name": "status",            
            "val": "0"
        }        
    ]
}
At the time of this event, the values of the variables have already been calculated and substituted into the queryString, but the values of these variables are not available in the onBeginProcessData() event. applic_status also displays 0 instead of 3.

In the event

Code: Select all

viewer.onInteraction = function (args) {
        if (args.action == 'Variables') {
            variables = args.variables;
        }
    }
the value of the following variables is available:

Code: Select all

{
    "applic_status": "3",
    "users_pre": [
        "200"
    ]
}
How do I get the calculated value of the users variable before sending the request to the server?
Thanks
r.polyakov
Posts: 11
Joined: Tue Dec 08, 2020 12:46 pm

Re: Get variable value in runtime before query string data complete

Post by r.polyakov »

Hello. Is there any information? Thanks.
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Get variable value in runtime before query string data complete

Post by HighAley »

Hello,

Why don't you use the expression from the variable instead of the variable?

You could also enable the Read Only property of the variable.

Thank you.
r.polyakov
Posts: 11
Joined: Tue Dec 08, 2020 12:46 pm

Re: Get variable value in runtime before query string data complete

Post by r.polyakov »

HighAley wrote: Mon Dec 14, 2020 9:09 am Hello,

Why don't you use the expression from the variable instead of the variable?

You could also enable the Read Only property of the variable.

Thank you.
Hello.
I need to collect a query string on the server instead of the client. Therefore, it is necessary to transfer all the necessary variables in the parameters to the server.
This method is used for the safety of generating the query string and avoiding user substitution of the query.
I found that the variable can be calculated in the method:
var param = Stimulsoft.Report.Engine.StiParser.StiParser.parseTextValue()

But when I call this method before sending the request to the server, I get an error:

Code: Select all

var a = new Stimulsoft.Report.Components.StiText;
a.name = "**DataSourceSqlCommand**";
a.page = command.report.Pages[0];
var param = Stimulsoft.Report.Engine.StiParser.StiParser.parseTextValue('{users}', a);
Result:

Code: Select all

stimulsoft.reports.min.js:57 Uncaught TypeError: Cannot read property 'engine' of undefined
    at Function.p.parseTextValue2 (stimulsoft.reports.min.js:57)
    at Function.p.parseTextValue (stimulsoft.reports.min.js:57)
    at eval (eval at StiHelper.process (viewer?lotnum=1&report_id=158&file_name=test_applics.mrt&user_id=21:37), <anonymous>:1:46)
    at StiHelper.process (viewer?lotnum=1&report_id=158&file_name=test_applics.mrt&user_id=21:51)
    at z.viewer.onBeginProcessData (viewer?lotnum=1&report_id=158&file_name=test_applics.mrt&user_id=21:133)
    at z.invokeBeginProcessData (stimulsoft.viewer.min.js:11)
    at ct.t.onBeginProcessData (stimulsoft.viewer.min.js:11)
    at ct.invokeBeginProcessData (stimulsoft.reports.min.js:66)
    at a (stimulsoft.reports.min.js:57)
    at c.m.process (stimulsoft.reports.min.js:57)
An error occurs when evaluating a variable:
var f = i.report.engine;
в методе p.parseTextValue2().

Can this method be used to calculate dynamic variables? If possible, how to properly initialize the second parameter for the parseTextValue() method so that it contains the required properties?
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Get variable value in runtime before query string data complete

Post by HighAley »

Hello.

We have an assumption about your issue.
We will try to make an improvement for you.

But it's better to see your report template with sample data to be sure that it will work out.

In any case, you need to make changes in the report too.
And it's better to use the expression from the variable in the SQL query.

Thank you.
r.polyakov
Posts: 11
Joined: Tue Dec 08, 2020 12:46 pm

Re: Get variable value in runtime before query string data complete

Post by r.polyakov »

HighAley wrote: Tue Dec 15, 2020 6:58 pm Hello.

We have an assumption about your issue.
We will try to make an improvement for you.

But it's better to see your report template with sample data to be sure that it will work out.

In any case, you need to make changes in the report too.
And it's better to use the expression from the variable in the SQL query.

Thank you.
Hello.
This is an example of our report.
Thanks
Attachments
test_report1.mrt
Report example
(7.8 KiB) Downloaded 156 times
r.polyakov
Posts: 11
Joined: Tue Dec 08, 2020 12:46 pm

Re: Get variable value in runtime before query string data complete

Post by r.polyakov »

Hello.
Do you need any more information from me?
Thanks.
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Get variable value in runtime before query string data complete

Post by HighAley »

Hello,

There is an error in your code:

Code: Select all

var a = new Stimulsoft.Report.Components.StiText;
a.name = "**DataSourceSqlCommand**";
a.page = command.report.Pages[0];
var param = Stimulsoft.Report.Engine.StiParser.StiParser.parseTextValue('{users}', a);
The third row should be

Code: Select all

a.page = command.report.pages[0];
Thank you.
Post Reply