- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2017 02:08 AM
Hi,
I wrote an onload client script :
function onLoad() {
var isAdmin = g_user.hasRole('admin');
if (isAdmin){
g_form.setReadOnly('u_withdraw_credit_in_advance',false);
g_form.setReadOnly('u_deposit_real_money',false);
} }
but the fields stay readonly.
I saw with the debug that a ui policy occurs after the client script and changes the fields back to readonly.
How can I implement it so it will override the ui policy?
Thank you in advance,
Shany
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2017 02:12 AM
Hello Shany Ben,
If you write Client script and UI policy on same field. Client script will execute first. You can write either client script or Ui policy for the same action.
For more info refer the below link.
A Race between UI Policy and Client script
Note: Always use UI policy instead of Client script which is a best practice.
ServiceNow Commnunity MVP -2018 class.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2017 02:16 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2017 02:26 AM
Hello shany ben,
1). Don't use the UI Policy and client script for same field, better to use UI Policy because it is alternate to the client script to make field read only Mandatory and Hidden.
2). Client script:Client scripts are shipped to the client (the browser) and run there instead of on the server. Users who know JavaScript can define scripts to run in the client browser
UI policy:UI policies offer an alternative to client scripts for dynamically changing information on a form. Administrators and users with the Personalize Rules [personalize_rules] or the UI policy administrator [ui_policy_admin] role can use UI policies to define custom process flows for tasks.
NOTE:As a best practice always use UI policy if you want to make field to be hidden,readonly,Mandatory
3). Basically UI Policy will run whenever condition is met i.e., onLoad and onChange. If you do not want UI Policy to run onLoad, you need to uncheck "On Load" checkbox.
Client Scripts runs onLoad, onChange, onSubmit & celledit.
Please Refer :
Difference between client script and ui policy
http://wiki.servicenow.com/index.php?title=Client_Script_Best_Practices#gsc.tab=0
Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke