Variable categories from code

Stimulsoft Reports.JS discussion
rpotyka
Posts: 13
Joined: Mon Jan 07, 2019 8:26 am

Variable categories from code

Post by rpotyka »

Hi,

I want to allow user to add variables to the report that are bound to category previously prepared in code (f.e. Tranlsations category). Later on when exporting the report to, say, pdf document, I'd like to iterate through all of the report variables, and when the category is "Translations" I want to do some operation like string localisation. Is there any way to do so? I checked the documentation but there's no method to add category of itself ( I tried method regBusinessObject2 but it didn't do anything or at least I did not notice so.
Thanks in advance,
Kind regards.
Lech Kulikowski
Posts: 6245
Joined: Tue Mar 20, 2018 5:34 am

Re: Variable categories from code

Post by Lech Kulikowski »

Hello,

Could you explain your issue in more details? How do you need add variables - in code or in the designer? if in the designer, you can add the category for variables directly in the Dictionary.

Thank you.
rpotyka
Posts: 13
Joined: Mon Jan 07, 2019 8:26 am

Re: Variable categories from code

Post by rpotyka »

As the topic says I wanted to add category from code so the user won't have to it themself and to ensure that the name is gonna be consistent for that category throughout ther reports (otherwiso user could just made a typo).
I found the solution however and it's to add variable from code when preparing report by creating new StiVariable and passing "Translation" category in the constructor. Then I just assign this variable via report.dictionary.variables.add method.
The category is then present on the designer and user can add new variables to that category without having to create it themselves.
Lech Kulikowski
Posts: 6245
Joined: Tue Mar 20, 2018 5:34 am

Re: Variable categories from code

Post by Lech Kulikowski »

Hello

Ok.
Please let us know if you need any additional help.

Thank you.
gegar
Posts: 31
Joined: Thu Dec 27, 2018 5:12 pm

Re: Variable categories from code

Post by gegar »

Hello

Someone have a example about this code.

Try this and it does not work.

// Load and show report
Stimulsoft.Base.Localization.StiLocalization.setLocalizationFile("localization/en.xml", true);
var report = new Stimulsoft.Report.StiReport();
report.loadFile("reports/report.mrt");

// New variable Address
var variables = new Stimulsoft.Report.Dictionary.StiVariable();
variables.name = "Address";
variables.alias = "Address";
variables.type = Stimulsoft.System.StimulsoftStringList;
variables.requestFromUser = false;
variables.value = "1234 Address ";

viewer.report = report;

Whay is my error.

Thank you.
Lech Kulikowski
Posts: 6245
Joined: Tue Mar 20, 2018 5:34 am

Re: Variable categories from code

Post by Lech Kulikowski »

Hello,

Please try to add the following code:
report.dictionary.variables.add(variables );

Thank you.
gegar
Posts: 31
Joined: Thu Dec 27, 2018 5:12 pm

Re: Variable categories from code

Post by gegar »

Hello

// Load and show report
Stimulsoft.Base.Localization.StiLocalization.setLocalizationFile("localization/en.xml", true);
var report = new Stimulsoft.Report.StiReport();
report.loadFile("reports/report.mrt");

var variables = new Stimulsoft.Report.Dictionary.StiVariable();
variables.name = "Address";
variables.alias = "Address";
variables.Type = Stimulsoft.System.StimulsoftType;
variables.requestFromUser = false;
variables.value = "1234 Address ";
report.dictionary.variables.add(variables);

viewer.report = report;

It's working.

Thank you.
Lech Kulikowski
Posts: 6245
Joined: Tue Mar 20, 2018 5:34 am

Re: Variable categories from code

Post by Lech Kulikowski »

Hello

We are always glad to help you!
Please let us know if you need any additional help.

Thank you.
gegar
Posts: 31
Joined: Thu Dec 27, 2018 5:12 pm

Re: Variable categories from code

Post by gegar »

Hello,

I update the new version 2023.

How can I do the same in JS and PHP?

Thanks
Lech Kulikowski
Posts: 6245
Joined: Tue Mar 20, 2018 5:34 am

Re: Variable categories from code

Post by Lech Kulikowski »

Post Reply