- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
ui policy setvisible=true
client script setVisible=false
Clien script over rides ui policy
but for setmandatory and set readonly ui policy over rides client script
so why in first case ,client script over rides ui policy
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Why Client Script Overrides UI Policy for setVisible:
Timing: Client scripts run after UI policies
Last Action Wins: Whatever executes last determines final visibility
No Form Validation: Visibility is just DOM manipulation
Why UI Policy Overrides Client Script for setMandatory/setReadonly:
Form Engine Control: UI Policy engine has higher precedence for form validation
Built-in Protection: ServiceNow protects mandatory/readonly settings at form level
Validation Priority: Form validation rules override client-side changes
Execution Order:
1. Form Loads
2. UI Policies Execute
3. Client Scripts Execute (onLoad)
4. Field Changes → UI Policies → Client Scripts (onChange)
Summary:
setVisible: Pure DOM manipulation → Last script wins (Client Script)
setMandatory/setReadonly: Form validation → UI Policy precedence (System protection)
Key Point: ServiceNow treats visibility as presentation but mandatory/readonly as form validation rules with different priority systems.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
Hi @aditya2byte ,
Are you using all three on same field? check script should not run after all loading then it will override.
Starting with the Istanbul release, ServiceNow began intentionally blocking g_form.setVisible() on mandatory fields. This ensures that the user can always see and fill out a required field, regardless of any conflicting client script logic. Before Istanbul, a client script with setVisible=false could successfully hide a field, potentially conflicting with UI policies and causing issues.
As always Client Script first then UI Policy runs.
Refer this article from SN: KB Article on setMandatory, setVisible issue
Thanks,
Bhimashankar H
-------------------------------------------------------------------------------------------------
If my response points you in the right directions, please consider marking it as 'Helpful' & 'Correct'. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
im not implementing all 3 conditions at time,im executing these 3 conditions separately .
For setReadonly and setMandatory ui policy over ride the client script but for setVisible ui policy doesn't
override the client script , so why
?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@aditya2byte Sometimes there be race condition between UI Policy and Client Script and we run into unexpected behaviour.
So follow the best practice on both the thing, do no use both on same variable.
Thanks,
Bhimashankar H
-------------------------------------------------------------------------------------------------
If my response points you in the right directions, please consider marking it as 'Helpful' & 'Correct'. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago - last edited a month ago
Best practice is not to use both client script and UI policy on same field. Where possible, create UI policy as it is the recommended option.
The issue you are facing could be due to race condition between Client Script and UI Policy and sometimes behavior could be unexpected due to exception scenarios. Refer below link for more details,
Mitigate this by having only UI policy and removing client script as both achieve same function.
If this helped to answer your query, please mark it as helpful & accept the solution.
Thanks,
Bhuvan