Client script that sets Urgency to ReadOnly doesn't run on load
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2022 11:04 PM
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);
}
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2022 11:41 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2022 11:50 PM
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);
}
}
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2022 11:55 PM
Hi
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2022 11:56 PM
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
Regards,
Abhijit
ServiceNow MVP