Update report variables after initial render

Stimulsoft Reports.JS discussion
Post Reply
reeax
Posts: 11
Joined: Tue Dec 05, 2017 7:29 pm

Update report variables after initial render

Post by reeax »

Hello

After the report has been rendered for the first time, I have to update some variables as in:

Code: Select all

report.dictionary.variables.getByName("bill_reference").valueObject = "NEWVALUE";
However, I can't find the way to "refresh" the report so the updated variables' values are used. I tried various combinations (here is a combo):

Code: Select all

report.dictionary.synchronize();
report.render();
viewer.renderHtml("bill");
The report is just re-rendered without modifications. Please advise.

Thanks
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Re: Update report variables after initial render

Post by Edward »

Hi Reeax,

Please check the following posts that might help you to set the report parameter correctly (in case if the parameter is something you would like to use as something more suitable for the task):
viewtopic.php?t=43181

Also please consider to use a double -pass for your report, if you calculate something after the first pass. This setting is available on the Report object in the report designer. Just click outside the page and the Report object will be selected.

And a value should be set just before the report.render(); method in your code.

Thank you,
Edward
reeax
Posts: 11
Joined: Tue Dec 05, 2017 7:29 pm

Re: Update report variables after initial render

Post by reeax »

Hi Edward,

I am having some inconsistent behavior. If I render the report for the first time and update report variables in the same function, let's say

Code: Select all

function a() {
  
  //generate report for the first time
  report.dictionary.variables.getByName("firm_name").valueObject = "FIRST COMPANY";
  ...
  viewer = new Stimulsoft.Viewer.StiViewer(options, "StiViewer", false);
  viewer.report = report;
  viewer.renderHtml("bill");

  //update firm name
  report.dictionary.variables.getByName("firm_name").valueObject = "SECOND COMPANY";
  report.render();
}
It works fine and the company name is updated in the viewer.

HOWEVER, if I move the "update firm name" part (both two lines) in another function (event handler, when a textbox value changes for example), the viewer is NOT updated. I checked in the debugger, report dictionary is correctly updated, however it seems that report.render() has no effect.

Is there some extra step to refresh the viewer, and why it works when everything is in the same function?
reeax
Posts: 11
Joined: Tue Dec 05, 2017 7:29 pm

Re: Update report variables after initial render

Post by reeax »

I suspect that the call to

Code: Select all

viewer.renderHtml("bill");
is asynchronous.

Indeed, when trying to "save rendered report to pdf" within the same function (immediately after renderHtml call), the PDF is empty. However, if I wrap that into setTimeout, PDF is saved correctly.

That is probably why updating the report variable within the same function seems to work -- the viewer is still not rendered (async).

The question remains, how do you update the report variable (ok, as above), and apply that change to the viewer (not ok), after the initial viewer render?
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Update report variables after initial render

Post by HighAley »

Hello.

Could you specify the moment when you want to update the variable?
Maybe it's better to use any event of the Viewer.

Thank you.
reeax
Posts: 11
Joined: Tue Dec 05, 2017 7:29 pm

Re: Update report variables after initial render

Post by reeax »

Hello,

As stated before, I want to update the report's variable when the user changes a field value in a form - then:

1) assign this new value to the report's variable (ok)
2) re-render the report and refresh the viewer
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Update report variables after initial render

Post by HighAley »

Hello.

Diв you try the Request from User variables?
You could get necessary data with our product and you don't need to write additional code to pass the variable's value.

Thank you.
reeax
Posts: 11
Joined: Tue Dec 05, 2017 7:29 pm

Re: Update report variables after initial render

Post by reeax »

Hello HighAley,

I don't know about the user variables, but the data has to come from outside your product. My request is very simple: render the report in the viewer for the first time, then update a variable value and refresh the viewer to reflect the new state.

Instead of talking alternatives, could you please give me a working code example of how to achieve this using stimulsoft API? Or is it not possible to update a variable and refresh the viewer ?

Thanks
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Update report variables after initial render

Post by Alex K. »

Hello,

You could set a value for a variable with next code:
report.dictionary.variables.getByName("var1").valueObject = "your value";

Thank you.
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Update report variables after initial render

Post by HighAley »

Hello.

All that you should do with the updated report is assign it to the Viewer.
And the report will be updates automatically.

Code: Select all

viewer.report = report;
Thank you.
Post Reply