UI policies versus client scripts
Quick answer
Pick the right client side tool, and stop writing script for things configuration already does.
Key takeaways
- UI policies handle visibility and mandatory without code
- UI policies run after client scripts unless ordered otherwise
- Catalog forms use their own policy and script records
- Client side rules are not security, they are convenience
What each does
A UI policy shows, hides, makes mandatory or read only based on a condition, with no code. A client script runs JavaScript on load, on change, on submit or on a cell edit. Both run in the browser and both run on every matching form load.
Order of execution
UI policies run after client scripts by default, which is why a client script that sets a field mandatory can appear to be ignored. The Reverse if false and Order fields on the UI policy control the interaction.
Choosing
Default to the policy.
- Visibility, mandatory and read only: UI policy
- Calculations, validation messages and server lookups: client script
- Catalog forms: catalog UI policy and catalog client script, they are separate records
- Anything that must be enforced: data policy or ACL, never client side alone
Want to learn this properly?
Our live, instructor-led ServiceNow Training covers this hands-on, with real projects and a certification path.
Check your understanding
Which is enforced on an import?
- A. Client script
- B. UI policy
- C. Data policy
- D. Onload script
Show answer
C. Data policy
Only server side rules apply to imports and API writes.
Which tool should set a field read only based on state?
- A. Client script
- B. UI policy
- C. Business rule
- D. ACL
Show answer
B. UI policy
That is exactly what UI policies exist for.