Page 1 of 1

Update report variables after initial render

Posted: Sat Dec 09, 2017 7:38 pm
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

Re: Update report variables after initial render

Posted: Mon Dec 11, 2017 4:30 am
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

Re: Update report variables after initial render

Posted: Mon Dec 11, 2017 10:34 am
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?

Re: Update report variables after initial render

Posted: Mon Dec 11, 2017 4:25 pm
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?

Re: Update report variables after initial render

Posted: Tue Dec 12, 2017 2:34 pm
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.

Re: Update report variables after initial render

Posted: Tue Dec 12, 2017 3:43 pm
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

Re: Update report variables after initial render

Posted: Wed Dec 13, 2017 5:42 pm
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.

Re: Update report variables after initial render

Posted: Thu Dec 14, 2017 3:47 pm
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

Re: Update report variables after initial render

Posted: Sat Dec 16, 2017 8:15 am
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.

Re: Update report variables after initial render

Posted: Mon Dec 18, 2017 7:50 am
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.