Client script that sets Urgency to ReadOnly doesn't run on load

Vikram Kee Dam2
Tera Expert

Hello

I have a requirement to set the Urgency field on a case form to ReadOnly if the 'assigned to' is not the logged in user, and make it available to edit if the 'assigned to' is the logged in user.

This is an old customer, with numerous customizations, which is why I'd rather not use an ACL, but a client script in stead.

This is what I wrote, and I can get it to set urgency field to ReadOnly on change, but not on load..

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}

if (newValue != g_user.userID) {
g_form.setReadOnly('urgency', true);
} else
g_form.setReadOnly('urgency', false);


}

4 REPLIES 4

Gayathri5
Tera Guru

Hi,

 

you have to make use of onLoad CLient script for this or else here put your code in isloading and try

 

var asto = g_form.getValue('assigned_to');

if(isloading){

if(asto == g_user.userID){

g_form.setReadOnly('urgency', true);

}

else{

g_form.setReadOnly('urgency', false);

}

 

Mark my answer correct, if it  helped you in any way.

 

Regards,

Gayathri

Aman Kumar S
Kilo Patron

Create one onload script:

function onLoad() {
   if (g_form.getValue("assigned_to") != g_user.userID) {
      g_form.setReadOnly('urgency', true);
   }
   else{
      g_form.setReadOnly('urgency', false);
   }
}

Best Regards
Aman Kumar

Snehangshu Sark
Mega Guru

Hi @Vikram Kee Damslora Willoch ,

 

It seems there must be a UI Policy that overwrites your client script changes. Find Ui Policy action for the assigned_to field and see if you find any luck.

 

Regards,

Snehangshu Sarkar

 

Please mark my answer as correct if it resolves your query.

 

Abhijit4
Mega Sage

Hi Vikram,

Use below script in you on change client script,

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

if (newValue != g_user.userID) {
g_form.setReadOnly('urgency', true);
} else
g_form.setReadOnly('urgency', false);

}

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit
Community Rising Star 2022

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP