Page Level scripts comprise:
- Page Validation scripts
- Page Hide scripts
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.s
The Page Script page opens - .
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
Editor : Report Tree > Page > Script | Main purpose: Validate the inputs made on the page and stop users from moving to other pages if input is not valid. |
Description: Some pages that you design in Reportal may sometimes have several input controls. Sometimes, it may be required to validate the combination of values in these controls. That should be done from this script. Add all validation errors into the validation error collection in the If the validation error collection has any items, Reportal will stop any navigation away from this page. | |
Example – Validate a page : if(page.IsSubmit) | |
Example – Write validation error message from a Text component for(var s in pageContext.ValidationErrors) | |
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.
- In the Hide Script field, enter the script
user.HasRole("Consultant")- .
The Page Script page opens, with the Hide Script field towards the top - .
Figure 2 - The Hide Script field
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.