Page 1 of 1

Setting Report Variables on the Server-Side

Posted: Thu Jan 05, 2023 6:48 pm
by gegar
Hello,

About the example Setting Report Variables on the Server-Side, the values for variables are ok.

Example
Name = 'Maria' Because in the

handler.php
$args->variables['Name']->value = 'Maria';

When I want to modify in design the same report Variables.mrt

The initial value of the Name is =""

I want to see the current value that updates it in handler.php Name='Maria'

If in the design I update the variable Name = "Maria12345" in the preview it shows only the Maria the original value changed in the handler.

What should I do?

Thank you.

Re: Setting Report Variables on the Server-Side

Posted: Fri Jan 06, 2023 10:53 am
by Max Shamanov
Hello,

When you change variable value in design time, it changes back when retrieve data from the server.
Could you explain your issue in more detail?

Thank you.

Re: Setting Report Variables on the Server-Side

Posted: Fri Jan 06, 2023 6:01 pm
by gegar
Hello,

I use the Stimulsoft 2019

The example code is the follows:

09. Set variable value from code
sti2.png
sti2.png (79.66 KiB) Viewed 10167 times
In the viewer, the value is ok -> test

In the designer, the value of Variable1 is -> default
In the preview, it is the same value -> default

I can update any value for Variable1 and the preview changes too.

*****************************************
But I have the other code that is better for me.

In the 2019 preview version for JS, I used the following code, I can create the variables or update the values.
sti3.png
sti3.png (78.7 KiB) Viewed 10167 times
Viewer the value is -> Val-ggs
The designer is the same value -> Val-ggs
In preview, is the same value -> Val-ggs
I can update any value for Variable1 and the preview changes too.

It's useful because whether or not you create the variables, the code creates the variables and updates the values.

**********************

In JS is working but the PHP code not is working.

How can I get the same behavior in the following code PHP?

<script type="text/javascript">
<?php
$handler = new StiHandler();
//$handler->license->setFile('license.key');
$handler->renderHtml();

/** https://www.stimulsoft.com/en/documenta ... ttings.htm */
$options = new StiViewerOptions();
$options->appearance->fullScreenMode = true;
$options->appearance->scrollbarsMode = true;
$options->height = '600px'; // Height for non-fullscreen mode

/** https://www.stimulsoft.com/en/documenta ... oyment.htm */
$viewer = new StiViewer($options);

/** https://www.stimulsoft.com/en/documenta ... report.htm */
$report = new StiReport();
$report->loadFile('reports/SimpleList.mrt');
$viewer->report = $report;
?>

function onLoad() {
<?php
$viewer->renderHtml('viewerContent');
?>
}
</script>


Thank you.

Re: Setting Report Variables on the Server-Side

Posted: Mon Jan 09, 2023 12:02 pm
by Max Shamanov
Hello,

Unforunately, at the current moment you can't create a variable using php code.
We are working on this issue.

But you can use JS code to create a variable and use it.
Please check the following link:
https://github.com/stimulsoft/Samples-J ... Script.php

Thank you.
#9758

Re: Setting Report Variables on the Server-Side

Posted: Mon Apr 17, 2023 4:10 pm
by Max Shamanov
Hello,

You can add a new variable to report by using the following code in PHP:

Code: Select all

$var1 = new \Stimulsoft\Report\StiVariable('var1', \Stimulsoft\Report\StiVariableType::String, "abc");
$report->dictionary->variables[] = $var1;

$var2 = new \Stimulsoft\Report\StiVariable('var2', \Stimulsoft\Report\StiVariableType::Decimal, 4.34);
$report->dictionary->variables[] = $var2;
Unfortunately, it is not possible to change or delete varibale via PHP code.
If you need to edit, or add with advanced properties - this is all available in JavaScript code in the report event onBeforeRender:

Code: Select all

$report->onBeforeRender = "onBeforeRender";
...

Code: Select all

function onBeforeRender(args) {
    let var1 = new Stimulsoft.Report.Dictionary.StiVariable('', 'var1', 'var1', '', Stimulsoft.System.Decimal, '4.34');
    args.report.dictionary.variables.add(var1);
}
Thank you.