Client Scripts vs. UI Policies

Client Scripts and UI Policies are both used to control behavior on forms and enhance user interactions in the client/browser.

Client Scripts

What is client script: JavaScript code that runs on the client side (in the user’s browser) when interacting with forms.

Types of Client Scripts:

    • onLoad – Runs when the form is loaded.

    • onChange – Runs when a field value changes.

    • onSubmit – Runs when the form is submitted.

    • onCellEdit – Runs when a cell is edited in a list.

Use Cases:

    • Complex logic (e.g., calculations, conditional logic)

    • Calling GlideAjax for asynchronous server communication

    • Dynamically manipulating form elements

Example

function onLoad() {
  g_form.setValue('short_description', 'Auto-filled on load');
}

Pros:

    • Highly flexible

    • Can use custom logic and external data

    • Supports complex interactions

Cons:

    • Requires JavaScript knowledge

    • Harder to maintain/debug compared to UI Policies

 

UI Policies:

What is UI Policy: Declarative (no-code/low-code) rules to control form elements like field visibility, read-only state, and mandatory status.

Use Cases:

    • Show/hide fields

    • Make fields mandatory or read-only

    • Run client-side scripts using UI Policy Actions

Example:

    • “If the Urgency field is ‘High’, then make the Impact field mandatory.”

Pros:

    • Easier to configure (no scripting required)

    • Clear and structured

    • Better for simple form rules

Cons:

    • Limited to predefined actions

    • Not suitable for complex logic

 

Comparison between client script and UI Policy

Feature Client Scripts UI Policies
Coding Required Yes (JavaScript) No (unless using scripts)
Complexity Handling Complex logic possible Simple logic only
Use Cases Dynamic behavior, Ajax calls Field visibility, read-only, etc.
Flexibility High Medium
Maintenance Harder to maintain Easier to maintain

 

Note: UI Policies execute after Client Scripts. If there is conflicting logic between a Client Script and a UI Policy, the UI Policy logic applies.

FAQ:

client script or ui policy which runs first

UI Policies execute after Client Scripts. If there is conflicting logic between a Client Script and a UI Policy, the UI Policy logic applies.

ui policy vs client script servicenow

UI Policies execute after Client Scripts. If there is conflicting logic between a Client Script and a UI Policy, the UI Policy logic applies.

LEAVE A REPLY

Please enter your comment!
Please enter your name here