In this article
A common use case for Reportal scripting is to be able to conditionally hide or show pages or elements of a page depending on either parameter values or user-specific values e.g. role.
Hide scripts can be applied to the following Reportal objects:
- Pages
- Folders
- Visual Components (Tables, Charts, Gauges, Hitlists, etc.)
Hide scripts are written in a specific input field:
Figure 1 - The Hide script input field
The object is hidden if the condition evaluates to True.
Hiding a Page Depending on User Role
In the following example, an end user list is associated with the report with the following users:
Figure 2 - An example of an End-User list with different roles set to End-Users
Within the end user permissions screen, there is a “role” field. This is an open text field that can contain any free text values. In our example, a role “Manager” has been assigned to user1
To hide a page for the manager role, enter the following script:
user.HasRole("Manager")Several roles can be combined in this hide condition using the AND (&&) or OR (||) logical operators:
User.HasRole("Manager") || User.HasRole("Sales")Hiding a Folder Based on Hierarchy Level
In this example, an end user list is associated with a report with the following users:
Figure 3 - An example of an End-User list with different report bases set to End-Users
Within the end user permissions screen, there is a report base field. This is used to establish the access level(s) of an organisational hierarchy that the user should be associated with when using personalised reporting. The values of this field are determined by the personalised question associated with the report.
Figure 4 - The Report Base field
In this example, we will hide a page for any users who belong to the hierarchy level “Midlands Region”:
user.PersonalizedReportBaseText == 'Midlands Region'Note: it is also possible to suppress on the Hierarchy ID. This is defined in the Database Designer tables within Forsta Professional Authoring (see the figure below)
Figure 5 - An example of a Database Designer table
In the case of multi-lingual reports, or where the text of the level defined in the hierarchy may change, it may be safer to use the Hierarchy ID for the hide condition as follows:
user.PersonalizedReportBase == 'R_MID'It is possible to hide the precode and child use by specifying the hierarchy node IDs separated with commas:
report.PersonalizedQuestion.InHierarchy(user.PersonalizedReportBase, "LatAm" ,"Eur") Hiding a Page Based on IP Address
It is also possible to hide a page based on matching to the viewer’s IP address. In the following example, a page is hidden if the users IP address is not equal to 85.142.100.30 :
user.UserIpAddress!="85.142.100.30"It is also possible to include or exclude across an IP address range, as in the following example:
!user.UserIsInIpRange("10.75.191.1","10.75.191.255"))Hiding a Chart Based on Table Values
The following example can be used to hide an object (e.g. a chart) based from aggregated data within tables. This example checks the value of the cell in the first row, and the first column in table “respondents” and will hide the chart if the value returned from this cell is more than 10.
report.TableUtils.GetCellValue("respondents", 1,1).Value>10Table ID is "respondents" and data is from Column 1 Row 1.
Further examples of using report.TableUtils.GetCellValue is explored elsewhere in the documentation
Hiding a Chart Based on the Value of a Parameter
Using parameters can provide a flexible way of storing values to be used to control report content, or to provide interactive control of content to the report viewer. Wider use of parameters is covered elsewhere in the documentation, but for this example, the following script will check the current set value of the string parameter “DisplayChart” which has values “Hide” or “Show” and will hide the chart if the value has been set to “Hide”.
state.Parameters.GetString("DisplayChart") == "Hide"Hiding a Component Based on the Value of a Parameter by Using Property IsNull
It is possible to hide components based on the value of a parameter by using property IsNull:
state.Parameters.IsNull("company") //If the parameter is null
!state.Parameters.IsNull("company") //If the parameter is not null
state.Parameters.GetString("company") == "HD" //HD in this case is the answer code and selected
!state.Parameters.GetString("company") == "HD" //HD in this case is the answer code and not selectedIt is possible to hide components based on multiple selected values by calling a function in the components script:
ClassName.FunctionName(state, ['2011','2012','2013','2014'])The called function is stored in the Codelibrary script:
class ClassName
{
static function FunctionName(state : ReportState, years) : String
{
var multiResponseA : ParameterValueMultiSelect = state.Parameters["p_Reportyear"];
var responseA : ParameterValueResponse;
var name : String = " ";
if(multiResponseA != null)
{
for(var x : int = 0; x < multiResponseA.Count; x++)
{
if(multiResponseA[x]=='2011'){name = '2011'}
if(multiResponseA[x]=='2012'){name = '2012'}
if(multiResponseA[x]=='2013'){name = '2013'}
if(multiResponseA[x]=='2014'){name = '2014'}
}
return name;
}
}
}
Hiding a Table when Exporting to Excel
It is possible to hide objects dependent on the "mode” that the report is being accessed. This is particularly useful for controlling the display of different report content to report viewer online, and what is contained within any report exports.
The following example will hide a table from being created in the contents of any exports to Excel:
state.ReportExecutionMode == ReportExecutionMode.ExcelExportThe ReportExecutionMode property has the following values:
Value | Description |
|---|---|
Design | Editing the page within Report Designer |
Web | Previewing or viewing the page as a Report viewer |
ExcelExport | Exporting to Excel |
PowerPointExport | Exporting to PowerPoint |
PdfExport | Exporting to PDF |