Loading

Creating a UI Policy

From ServiceNow Wiki
Jump to: navigation, search
Forms
Related Topics

Contents

1 Overview

UI policies offer an alternative to client scripts for dynamically changing information on a form. Administrators and users with the Personalize Rules [personalize_rules] or the UI policy administrator [ui_policy_admin] role can use UI policies to define custom process flows for tasks.

Note
Note: UI policies are not supported on search screens.


2 Creating a UI Policy

A UI policy can only check fields that are present on a form. Ensure that any field called by a UI policy exists on the form.

To create a UI policy:

  1. Navigate to System UI > UI Policies.
  2. Click New.
  3. Right-click the form header and select View > Default view or Advanced (starting with the Eureka release).
  4. Fill in the form, as appropriate (see table).
  5. Click Submit.
A UI policy that sets all fields on the Incident table to read-only when the incident state is set to closed.

Note
Note: You might need to personalize the form to see all the fields below.
Field Description
Table The table for the form to be modified.
Active The UI policy's active status. Only active UI policies are applied.
Short description Short summary of the UI policy.
When to Apply
Conditions The conditions which, if fulfilled, cause the UI policy to be applied. Conditions are built with the condition builder. To set conditions using a script, use a client script instead. Conditions are only rechecked if a user manually changes a field on a form. If the change is made by a UI action, context menu action, or through the list editor, it is not evaluated.

The field must be on the form to be checked by a UI policy. To test the value of a field but hide the field from users, add the field to the form and use UI policies to hide it from users' view. This requirement also prevents dot-walked fields from being used as conditions.

Global

[Advanced view]

Option for specifying whether the UI policy applies to all form views. If this check box is cleared, the UI policy is view-specific.
View

[Advanced view]

Option for indicating which view or views the UI policy applies to. This is visible only if Global is not selected.
Reverse if false

[Advanced view]

Option for specifying that the UI policy action should be reversed when its UI policy's conditions evaluate to false. In other words, when the conditions are true, actions are taken and when they change back to false, the actions are reversed (undone).
On load

[Advanced view]

Option for specifying that the UI policy behavior should be performed On Load as well as when the form changes.
Inherit

[Advanced view]

Option for specifying whether extended tables will inherit this UI policy.
Script
Run scripts

[Advanced view]

Option for specifying whether advanced behavior can be scripted for both true and false conditions.
Execute if true

[Advanced view]

A script that executes if the UI policy's conditions are fulfilled. This field is available only if Run scripts is selected.
Execute if false

[Advanced view]

A script that executes if the UI policy's conditions are not fulfilled. This field is available only if Run scripts is selected.
Other fields
Run scripts in UI type The UI type for this UI policy: Desktop, Mobile, or Both (available starting with the Dublin release).
Related List: UI Policy Actions
Table [Read-Only] Field the UI policy action applies to.
Field name Field on the selected table to which the UI policy will perform an action if true.
Mandatory Choice list for specifying how the UI policy affects the mandatory state of the field. Choices are:
  • Leave alone
  • True
  • False
Visible Choice list for specifying how the UI policy affects the visible state of the field. Choices are:
  • Leave alone
  • True
  • False
Read only Choice list for specifying how the UI policy affects the read-only state of the field. Choices are:
  • Leave alone
  • True
  • False
UI action
Default view or Advanced view Changes the form view to the default or advanced view. The fields change based on the view.

2.1 Example

Create a UI policy to implement the following controls in the Incident form when the state changes to Resolved:

  • Make a Close Notes field mandatory.
  • Hide the Opened by field.
  • Make the Priority, Severity, and Urgency fields read-only.
  • Run a client script that displays an alert message.

To create the UI policy:

  1. Navigate to System UI > UI Policies.
  2. Click New.
  3. Supply the following information:
    • Table: Incident
    • Conditions: [Incident state] [is[ [Resolved]
    • Reverse if false: Select this check box. The UI policy will be reversed if the incident state is not Resolved.
    • On load: Select this check box to perform the actions when the form is loaded or when the condition changes.
  4. Right-click in the header bar and select Save from the context menu.
    The UI Policy Actions related list appears.
  5. Click New in the Related List.
  6. Provide the following information:
    • Field name: Close notes. This makes the Close notes field mandatory.
    • Mandatory: True
    • Visible: Leave alone
    • Read Only: Leave alone
  7. Click Submit.
  8. Repeat the process to create UI policy actions to hide the Opened by field, and to make the Priority, Severity, and Urgency fields read-only.

3 Defining Client Scripts

The UI Policy form enables an administrator to create client scripts that run onChange when the UI policy's conditions are met (Execute if True) or not met (Execute if False). To display these scripting fields, select the Run scripts check box. For example, to display an alert to the user when the Incident state field changes to Resolved, create the following script in the Execute if true field:

function onCondition() {
   alert('You changed the "Incident state" to Resolved. Please enter your comments in the "Close notes" field.');
}

4 The On load Check Box

The On load check box controls whether a UI policy runs every time a form is loaded (if the conditions are satisfied). The following example demonstrates how to use this feature.

Scenario: The Awaiting user info state is available on the Incident form. An administrator does not want an incident to enter this state unless the user provides an explanation to the customer.

  • The administrator creates a UI policy for the Awaiting user info state that makes the Additional comments field mandatory.
  • The administrator clears the On load check box so that the UI policy applies only when the state changes to Awaiting user info.
    If the On load check box were selected, the UI policy would apply every time a user opens an incident in the Awaiting user info state.

5 View-Specific UI Policy

By default, the Global UI policy applies to all form views. However, a UI policy can be specific to a view. For example, a UI policy can be defined for just the itil view of a form. Two fields control this:

  • Global
  • View

If the Global check box is cleared, the View field is displayed. Select a view, and the UI policy applies only to that view of the form.

6 Converting a UI Policy to a Data Policy

To make a UI policy the default setting or apply it to import sets or data imported by SOAP web services, convert the UI policy to a data policy. Converting a UI policy to a data policy deactivates the UI policy. To retain the policy in the UI, ensure that the Use as UI Policy on client check box is selected on the data policy record. For more information, see Data Policy.

For a UI policy to be eligible for conversion to a data policy, the following conditions must all be met on the UI Policy form:

  • The Run scripts check box must be cleared
  • The Global check box must be selected
  • None of the UI policy actions can have Visible set to True or set to False (it must be set to Leave Alone)

To convert a UI policy to a data policy:

  1. Navigate to System UI > UI Policies.
  2. Open an existing UI policy.
  3. Under Related Links, click Convert this to Data Policy.
    A new data policy record is created.
  4. Edit the fields on the data policy record as necessary. For details about the fields, see Data Policy Fields.

7 Service Catalog UI Policy

UI policies can be applied to service catalog items. For details, see Service Catalog UI Policy.

8 Wizard UI Policy

UI policy is available for wizards. For details, see WIzard UI Policy.

9 Enhancements

9.1 Eureka

  • The UI Policy form provides a default view that provides a simplified form and an advanced view that shows additional fields.

9.2 Dublin

  • The Run scripts in UI type field has been added to accommodate UI policies defined for the desktop UI, smartphone interface, or both.
Was this article helpful?
Yes, I found what I needed
No, I need more assistance
Views
Personal tools