Creating a UI Policy that includes a UI Policy Action to run a script allows you to execute custom JavaScript on the client side when certain conditions on a form are met. If you want to use a script to set the Impact, Urgency, and Priority fields when the caller is a VIP, follow these steps to create the UI Policy with the script:
-
Navigate to UI Policies:
Go to your ServiceNow instance and type "UI Policies" into the filter navigator and select it.
-
Create New UI Policy:
Click the "New" button to create a new policy. Fill in the form with the following details:
- Name: Enter a meaningful name (e.g., "VIP Caller Priority")
- Table: Select the appropriate table (e.g., Incident [incident]) from the dropdown list.
- Active: Ensure the active checkbox is selected.
-
Conditions:
Define your condition for the policy to apply when the caller is a VIP. You may need to create a custom condition that references the caller's VIP status.
-
UI Policy Actions:
Do not define conventional field-value actions if you intend to use a script.
-
UI Policy Scripts:
- Check the box for "On Load" if this script should run when the form is loaded.
- At the bottom of the UI Policy form, in the "Related Links" section, click on "Advanced view" to open more options.
-
Run Script:
There is a field labeled "Run script" where you can write a custom script to set the field values. Enter your script there. Below is an example script that could be modified according to your instance's configuration:
function onCondition() {
// Check if the caller is marked as VIP
var vipField = g_form.getValue('caller_id.vip'); // Replace with actual field for VIP on the user record
if (vipField == 'true') { // or if (vipField == '1') { depending on how the VIP attribute is stored
g_form.setValue('impact', '1'); // Replace '1' with the value for 'High' in your instance
g_form.setValue('urgency', '1'); // Replace '1' with the value for 'High' in your instance
var priority = '1'; // Replace with the sys_id or index of the 'Critical' priority in your instance
g_form.setValue('priority', priority);
}
}
Make sure to replace 'caller_id.vip', '1', and the priority value with the actual field names and values that correspond to your instance configuration.
- Save the UI Policy:
Click the "Submit" or "Update" button to save the new UI Policy.
Testing your UI Policy is critical. Make the necessary adjustments if fields or values are not set as expected. Do the testing on a sub-production or test instance before applying these changes to your production instance to prevent any unintended consequences.
Remember to ensure that your script closely follows the best practices of ServiceNow's client scripting and aligns with your organization's governance policies. When you're writing scripts inside UI Policies, use the g_form object to interact with form fields. This example script assumes that the VIP property is directly accessible via dot-walking on the caller_id field, which may not always be the case depending on your setup. You may need to use a GlideAjax call to retrieve information not immediately available on the form.