Script examples
Having introduced the basic elements of client-side scripting and how and where to use it, we can take a look at some examples of scripts to further our understanding.
We'll start by looking at some client script examples.
In this first example, we'll use an onLoad client script to show and hide form sections based on the logged-in users' roles. We'll only show the related records form section on the incident form if the logged-in user has the itil_admin role:
function onLoad() {
if (g_user.hasRole('itil_admin')) {
g_form.setSectionDisplay('related_records', false);
}
}As you can see in the example, we are using g_user's hasRole method to determine whether the logged-in user has the required role. If they don't, then we use the g_formsetSectionDisplay method to hide the form section. Putting this client script as an onLoad type allows us to ensure that this form section is immediately hidden from the user.
I have often used this type of script before to hide sensitive...