In this article
To access the Page Script functionality:
- Right-click on the report page in the Report toolbox and select Script from the drop-down menu.
- Type the required script into the appropriate field, compile to test it, and save.
The Page Script page opens - show me.
Figure 1 - The Page Script page
Note: All visual components on a page that have Hide scripts also have a Hide script in the Report Master.
Page Validation Script
This script is used to validate the inputs made on a page and prevent users from moving to other pages if the input is invalid. Some pages that you design in Reportal may have several input controls, and it may be necessary to validate the combination of values in these controls. This can also be achieved using this script.
Add all validation errors into the validation error collection in the pageContext object, then use the values from one or more Text controls to output these messages.
If the validation error collection has any items, Reportal will stop the user navigating away from the page.
To enter the script editor, right-click an appropriate page in the Report Tree and select Script > Render.
Example – Validate a page:
if(page.IsSubmit)
{
if(state.Parameters.IsNull("p_date_1")||state.Parameters.IsNull("p_date_2")){
this.pageContext.ValidationErrors.Add("Please fill both dates");}
else{var d1 : DateTime = state.Parameters.GetDate("p_date_1");
var d2 : DateTime = state.Parameters.GetDate("p_date_2");
if(d2 < d1)
{
this.pageContext.ValidationErrors.Add("End date should after start date");
}
}
}
Write validation error message from a Text component
for(var s in pageContext.ValidationErrors)
output.Append(s + "<br>");
Page Hide Script
You can use this functionality to hide a report page or a visual component on a page from, for example, a specific role. If the expression in the Hide Script field evaluates to TRUE, the page will be hidden.
Note: All visual components on a page that have Hide scripts also have a Hide script in the Report Master.
A possible scenario could be that you wish to selectively hide a report page based on the viewer's role. Note that you set the viewer's role in a text field under End User Permissions.
For this example assume that you have a number of end users. Some have the role of "Manager", while the others have the role of "Consultant". Assume you have created a page that you wish to be accessible only to those with the Manager role and you want to hide it from the end users with the Consultant role.
- Right-click on the page in the Report toolbox and select Script from the drop-down menu.
The Page Script page opens, with the Hide Script field towards the top - show me.
Figure 2 - The Hide Script field
- In the Hide Script field, enter the script user.HasRole("Consultant") - show me.
Figure 3 - The script
For the managers this script will evaluate to FALSE, so they will be able to see the page. However for the consultants it will evaluate to TRUE, so the page will be hidden.