- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I was testing behaviour of client script and ui policies, where field A was there on which i configured a client script which does make that field readOnly and a UI policy which makes that field mandatory,
Form behaviour was such that, the field became mandatory if field is empty and it became readOnly when field was filled by any data.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
UI Policies override Client Scripts: UI Policies always execute last and win any conflict.
Mandatory wins over Read-Only: ServiceNow never allows a field to be both. It prioritizes mandatory so users can still enter data.
The Result
When Empty: The UI Policy forced the field to be mandatory, overriding the Client Script's read-only rule.
When Filled: The UI Policy stopped acting, allowing the Client Script to successfully make the field read-only.
Best Practice
Delete the Client Script and use one UI Policy with the condition Field A is not empty to handle both states automatically.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @dellyou088
First I will suggest you to go through script courses or videos where you will get good idea of Client script , UI policy , when we use them
Refer:
Client Script vs UI Policy: What Happens When Conditions Conflict in ServiceNow
https://www.youtube.com/watch?v=Poo_yqfRZYg
https://www.youtube.com/watch?v=K08lYNeq83k
Secondly , At same time a field can not be mandatory and read only.
Lastly , When a form loads or changes, ServiceNow executes client-side configurations in a specific sequential order:
- Client Scripts (including onLoad and onChange) run first.
- UI Policies run second, which means they execute after Client Scripts
Because UI Policies run last, they get the final say and will overwrite any conflicting configurations previously set by a Client Script.
Second thing is that
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
UI Policies override Client Scripts: UI Policies always execute last and win any conflict.
Mandatory wins over Read-Only: ServiceNow never allows a field to be both. It prioritizes mandatory so users can still enter data.
The Result
When Empty: The UI Policy forced the field to be mandatory, overriding the Client Script's read-only rule.
When Filled: The UI Policy stopped acting, allowing the Client Script to successfully make the field read-only.
Best Practice
Delete the Client Script and use one UI Policy with the condition Field A is not empty to handle both states automatically.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Condition - field A is not empty
Reverse if false - check the checkbox
Read only - true
Mandatory - false
If the condition is not met( field A is empty)
Read only - false
Mandatory - true