- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2025 12:04 AM
Hi Everyone,
If UI policy makes field mandatory and I use client script to make it non mandatory which one will work?
On-change client script I understand will make it in non mandatory, what about client on load script?
Regards,
Zeba
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
Hi @ZebaT
In ServiceNow, when both a Client Script and a UI Policy apply to the same field, the execution order matters. Client Scripts run first, followed by UI Policies.
So, in your scenario:
- If the Client Script makes the field non-mandatory,
- The UI Policy executes afterward and overrides it, making the field mandatory again.
This means the UI Policy will take precedence because it runs later in the sequence.
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
Hi @ZebaT
I agree with @J Siva here.
Client on load executes first, followed by UI policy. You can test it out in PDI:
1) Create a UI policy making Description field mandatory:
2) Create a client script on load making Description non-mandatory:
3)Result: we can see, UI policy executes after Client script on-load:
lets reverse condition and check again, UI policy makes Description field non-mandatory
2) Client scripts for Description Field making it Mandatory:
3) Result: Again UI policy executes after client script, hence Description is non-mandatory:
If you find this answer useful, please mark it as helpful/solution accepted
Thanks and Regards,
Mohammed Zakir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
Thanks @J Siva @Ankur Bawiskar @Mohammed8 for reply,
one more thing I wanted to know
For example if I want to make 5 field mandatory, should I go for client script or one UI policy with 5 action. What's best practice. What I have read is UI policy for simple is best practice. What's your opinion on this?
Thanks,
Zeba
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
In between UI Policies and Client Scripts , Client scripts execute first always and then UI policies run.
Hence, UI policies will always override the client script's logic.
for e.g If you are making a field mandatory using Client script and thus adding a UI policy to make the same field non mandatory. The result will end up like the field is non mandatory as the logic of the UI policy executes after the client script.
Hence, Client script does preceed UI policy. But, the UI policies still win by overriding the logic .
If my response was helpful, please mark it and accept the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
HI @ZebaT
Obviously, Client Script runs first, and UI Policy Runs after the client scripts is executed.
Talking about preferences of being the right one, that depends on what you are trying to achieve in terms of requirements or real use cases.
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.
********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect
Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago - last edited 4 weeks ago
It depends on use case. If its simple and straight forward go for UI policy and UI policy actions and its beginner friendly.
Here is the link having same discussion:
Thanks and Regards,
Mohammed Zakir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
Hi @ZebaT
In ServiceNow, when both a Client Script and a UI Policy apply to the same field, the execution order matters. Client Scripts run first, followed by UI Policies.
So, in your scenario:
- If the Client Script makes the field non-mandatory,
- The UI Policy executes afterward and overrides it, making the field mandatory again.
This means the UI Policy will take precedence because it runs later in the sequence.
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
Hi @ZebaT
I agree with @J Siva here.
Client on load executes first, followed by UI policy. You can test it out in PDI:
1) Create a UI policy making Description field mandatory:
2) Create a client script on load making Description non-mandatory:
3)Result: we can see, UI policy executes after Client script on-load:
lets reverse condition and check again, UI policy makes Description field non-mandatory
2) Client scripts for Description Field making it Mandatory:
3) Result: Again UI policy executes after client script, hence Description is non-mandatory:
If you find this answer useful, please mark it as helpful/solution accepted
Thanks and Regards,
Mohammed Zakir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
Thanks @J Siva @Ankur Bawiskar @Mohammed8 for reply,
one more thing I wanted to know
For example if I want to make 5 field mandatory, should I go for client script or one UI policy with 5 action. What's best practice. What I have read is UI policy for simple is best practice. What's your opinion on this?
Thanks,
Zeba
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago - last edited 4 weeks ago
It depends on use case. If its simple and straight forward go for UI policy and UI policy actions and its beginner friendly.
Here is the link having same discussion:
Thanks and Regards,
Mohammed Zakir
