Client script overriding the UI policy and making a field editable

shany_b
Kilo Contributor

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

1 ACCEPTED SOLUTION

Karthik Reddy T
Kilo Sage

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.


Karthik Reddy T.
ServiceNow Commnunity MVP -2018 class.

View solution in original post

6 REPLIES 6

Tapan kumar
Kilo Explorer

I have the same question.


Karthik Reddy T
Kilo Sage

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.


Karthik Reddy T.
ServiceNow Commnunity MVP -2018 class.

for same scenario in my instance UI Policy executed first, how did that happened?

 

Gaurav Bajaj
Kilo Sage

Better write a UI policy only instead of using client script as their order is never predicted among themselves and between client script and UI Policy, it will run first.


Y the u can use script in a UI policy to achieve it.



find_real_file.png