set assigned to mandatory when state changes
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2024 04:05 AM
I need to write on change client script that if state field Changes directly from "new" (1) to any other status except "in progress" (2), assigned to field should be mandatory.
I tried this:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if (oldValue == 1 && newValue != 2) {
g_form.setMandatory('assigned_to', true);
}else {
g_form.setMandatory('assigned_to', false);
}
}
3 REPLIES 3
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2024 04:07 AM
so the above script is not working fine?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards,
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2024 04:48 AM
no it doesnt work

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2024 06:24 AM
Try like this
if (oldValue.toString().indexOf("1") > -1 && newValue.toString().indexOf("2") < 0) {
g_form.setMandatory('assigned_to', true);
} else {
g_form.setMandatory('assigned_to', false);
}
Thanks,
Narsing