Make 'state' field readonly if logged-in user & caller are same on incident form using client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2023 04:43 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2023 04:48 AM
Hi @PTR
Have you tried any client script yet and facing issue?
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2023 05:03 AM
Hi @PTR ,
Please find the below onChange of Caller Client script to achieve your above use case.
Code:-
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (newValue == g_user.userID) {
g_form.setReadOnly('state', true);
} else {
g_form.setReadOnly('state', false);
}//Type appropriate comment here, and begin script below
}
Please find the below screenshot.
Please mark my answer as helpful and accept it as a solution, if it helps!!
Thanks & Regards,
Suma.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2023 05:04 AM - edited ‎05-19-2023 05:08 AM
Hi @PTR
Please find the onChange Client Script on Caller field below:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var callerID = g_form.getValue('caller_id');
if (g_user.userID == callerID) {
g_form.setReadOnly('state', true);
} else {
g_form.setReadOnly('state', false);
}
}
There is an existing OOTB UI Policy "Make fields read-only on close" Which will conflict with it. Inactivating it, script works fine. You have to modify this UI Policy accordingly to script is also not conflicting and purpose of UI Policy is also fulfilled.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2023 06:39 AM
hi ,
please try below On change client script on "caller" field
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var callerID = g_form.getValue('caller_id');
var user=g_user.userID;
if (user == callerID) {
g_form.setReadOnly('state', true);
}
else {
g_form.setReadOnly('state', false);
}
}