In this article
Codelibrary Script
This script is used to write common script classes available from any other scripts in the report. Multiple Codelibrary scripts can be added to a report; stored in the Codelibrary Script folder node in the Report toolbox. Many classes can be added to each script.
In this script you can write your own classes. These classes will typically be used as follows:
- When you have some common logic that should be used from several of the other scripts in the report.
- When the logic in a hide script is too complex to be expressed in an expression, you can implement this logic in a common class and just call this method from the hide script.
If you want to use any of the objects available in other script, you have to pass them as parameters to the code library script.
To add a new script, in the Report toolbox right-click on the Codelibrary Script folder node and select Add Codelibrary Script.
To enter the script editor, open an appropriate codelibrary script in the Codelibrary Script folder in the Report tree.
Codelibrary:
class MyLib{
function MultiplyBy100(value : Decimal) : Decimal
{
return value * 100;
}
}
Usimg the library in a Text component:
if(!state.Parameters.IsNull("p_decimal"))
{
var lib : ReportCommon.MyLib = new ReportCommon.MyLib();
var val : Decimal = state.Parameters.GetDecimal("p_decimal");
output.Append(lib.MultiplyBy100(val));
}
All Codelibrary scripts will be stored in the Codelibrary Script folder node in the Report toolbox. Any Codelibrary scripts that already exist in a report when Version 16 is installed will be moved automatically to this folder. You can export all Codelibrary scripts at once in a .zip archive by right-clicking on the Codelibrary Script folder node and selecting Export scripts.
Linked Code Library Script
Linked code library script provides a means of hosting common Reportal script code in an external repository, such as Github, that can be then referenced in Reportal reports. Using a linked code library allows companies to easily maintain and update common code snippets that may be used across several reports, without the need for changing the code in each individual report.
To add a new script, in the Report toolbox right-click on the Linked Codelibrary Script folder node and select Add Linked Codelibrary Script.
To enter the script editor, open an appropriate linked codelibrary script in the Linked Codelibrary Script folder in the Report tree.
The Linked Codelibrary Script properties
The following properties are available:
- Source Control Type - Git Hub
- Shared Code Library URL - indicates an URL pointing to a ZIP archive stored at an external resource, e.g. GitHub. For the GitHub, there are two kinds of URLs supported:
- UI: https://github.com/user_name/repo_name/archive/f09a2af4285d6917da222c73455b6a7bacdb90d5.zip.
- API: https://api.github.com/repos/user_name/repo_name/zipball/f09a2af4285d6917da222c73455b6a7bacdb90d5.
The API URL has the following varieties:
- The latest version of a branch: https://api.github.com/repos/user_name/repo_name/zipball/master.
- A particular version of a branch (by a commit SHA): https://api.github.com/repos/user_name/repo_name/zipball/f09a2af4285d6917da222c73455b6a7bacdb90d5.
- A Tag: https://api.github.com/repos/user_name/repo_name/zipball/Tag1.
- API Key - a security key. For the GitHub, it is an OAuth2 access token bearer.
- Auto Check Version - when this option is checked, the version will be queried every time, when the report is opened in designer. If a new version detected, the library is updated. A message will be sent to the Quality Control validation window.
Note: This option is not applicable when the Enforce Updating option is turned on.
- Enforce Updating - checking this option enforces the update which will be done ignoring ETag, even when the version is the same.
- Last Updated - this indicates the date of the last update.
- ETag - this indicates the SHA code of the current imported library version. It is taken for ZIP and used to detect a version change.
- Updated by - this indicates the username of the last user who downloaded the library scripts.
Example - Linked Codelibrary:
class MyLib{
function MultiplyBy100(value : Decimal) : Decimal
}
return value * 100;
}
}Permission Scripts
This script is used to validate that the current user has permission to all current values of all parameters. It can also be used to initialize required values for report parameters. This script is always called first for each page in the report and before exporting any object to MS Office or other format for that report.
Even though you for example mask the content of a parameter used in a drop-down to limit the user’s access to specific values, you should also write a permission script to take care of the permission control. This for the following reasons:
- Even if input controls are masked, hostile users may attempt to hack the report using a tool to post other values to the input controls.
- If for example a report user has access to a specific parameter value at a certain point of time, they can save a page with the given value to a private folder (Viewer Presentation component). As the report designer you may want to revoke this user's access at some point. If so, the permission script will then deny this user access to the previously saved page.
In some cases you may want to design a report using projects that are not in the report data source. This may be the case if you are continuously making new projects available to a report and do not want to modify the report and re-publish it each time. Two steps are required to achieve this:
- Go to the Viewer Project Permission page and grant access to projects outside data source.
- Explicitly grant access to required projects in this script.
If you wish to initialize or change parameter values based on other parameter values, this can also be done in this script. Alternatively use the page script for this. These two scripts are the only scripts where you are allowed to change parameter values.
To enter the script editor, select Permissions - Permissions Script.
Allowing Access to Project Not in Datasource:
// Authorizes project outside datasource
state.AuthorizeProjectAccess("p0559090");
Raise Permission Denied:
var unit : String = state.Parameters.GetString("p_unit");
if(user.UserId == "someuser" && unit != "someunit")
HasPermission = false;