Lesson 1
In ServiceNow, Client Scripts, Business Rules, and UI Actions are powerful scripting tools used for customizing and automating functionality. Client Scripts run in the user’s browser, UI Policies control field visibility and behavior, and Business Rules execute on the server-side when records are modified. UI Actions are used to create buttons and links for user interaction.
-
Purpose:
Client Scripts are used for client-side (browser) logic, such as manipulating form fields, validating input, and providing user feedback.
-
Execution:
They run when a form is loaded, modified, or submitted, and can respond to user actions in real-time.
-
Types:
Common types include
onLoad,onChange,onSubmit, andonCellEdit. -
Example:
Making a field mandatory when a certain condition is met, or displaying an alert message based on user input.
-
Key Features:
g_formobject provides access to form elements,g_userfor user information, andg_scratchpadfor sharing data between client and server.
- Purpose: Business Rules are server-side scripts that automate tasks and enforce data integrity on the server.
- Execution: They run when records are inserted, updated, deleted, or queried.
- Types: Can be configured to run
before,after,async, ordisplayoperations. - Example: Setting a field value based on a calculation, creating a task when an incident is created, or enforcing data validation rules.
- Key Features:
currentobject represents the current record,previousfor the previous record state, andgsfor server-side functions.
- Purpose: UI Actions are used to create buttons, links, and context menu items on forms and lists.
- Execution: They run when a user clicks on the UI Action.
- Types: Can be client-side, server-side, or both.
- Example: Creating a button to close an incident, or a link to open a related record.
- Key Features:
actionobject provides control over the UI action’s behavior, such as redirecting the user or showing messages.
-
Purpose:
UI Policies are used to control field visibility, read-only status, and mandatory status based on conditions.
-
Execution:
They run on the client-side and are triggered when the form is loaded or modified.
-
Key Features:
UI Policies are a declarative way to manage field behavior, making them easier to configure than client scripts for simple field manipulations.
-
Example:
Hiding a field when a certain condition is met, or making a field mandatory based on the value of another field.
- UI Policies: Run first when the form is loaded.
- Client Scripts: Run after UI Policies, allowing for more complex client-side logic.
- Business Rules: Run on the server after the form is submitted or modified.
- UI Actions: Run when a user clicks on the UI Action button or link.
- For basic field manipulations and user interface behavior, UI Policies are often the best choice.
- For more complex client-side logic, such as real-time form validation or data manipulation, Client Scripts are appropriate.
- For server-side logic, such as data validation, record creation, or complex calculations, Business Rules are essential.
- For user interactions on forms and lists, UI Actions provide the buttons, links, and context menu items.
