Set mandatory using on change client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2024 05:43 AM - edited 01-07-2024 05:55 AM
Hi,
I am trying to write on change client script, so that if "state" field changes directly from "new" (1) to any other status except "in progress" (2), assigned to field will be mandatory on SOW.
I tried this:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2024 06:27 AM
Can you try with UI Policy instead of Client Script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2024 06:24 AM
Hi @Sahar_Kaizer ,
you are code is correct but isTemplate method is missing on you onchange client script
Try below code it will work.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (oldValue == 1 && newValue != 2) {
g_form.setMandatory('assigned_to', true);
} else {
g_form.setMandatory('assigned_to', false);
}
}
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2024 06:26 AM
it doesnt work...
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2024 06:31 AM
Hi @Sahar_Kaizer ,
I have tried this it is working for me. can you just use the script which i provided.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar