Development · LessonBy Praveen T, ServiceNow Trainer, 9 yrs · Published · ServiceNow · all levels
UI policies versus client scripts
Pick the right client side tool, and stop writing script for things configuration already does.
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
Practice challenge
+0 XPStreak ×0
Question 1 of 2
Which is enforced on an import?
Frequently asked questions
Why did my client script mandatory setting disappear?
A UI policy ran afterwards and reset the field. Change the policy or set the script order.
Do UI policies work on the portal?
Catalog UI policies apply to catalog items in the portal. Standard form UI policies apply to the platform UI and workspaces.