help with a client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2025 03:28 PM
Hello,
I need help with an onChange client script on the TASK level. Once a Task has been created for a certain catalog item, when the State for the TASK changes to 'Closed Complete' I would like a certain field to be mandatory. Can someone help me with that please?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2025 03:50 PM
Hi @Jen11
you can write an ui policy on sc task on the catalog item whenever state is closed complete you can make field mandatory.
Thanks and Regards
Sia Venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2025 05:42 PM
Hi @Jen11
If it is a field on sc_task table, then you can write UI policy to make the field mandatory when catalog item and state conditions matches.
If you are trying to make a catalog variable as mandatory then you may write on-change client script on state change. Sample script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2025 08:14 PM
it's a field or it's a variable which needs to be mandatory?
If it's a variable then you will have to write onChange client script on State field on sc_task
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (g_form.getValue('state') == '3' && g_form.getValue('variables.variableName') == '') {
g_form.setMandatory('variables.variableName', true);
}
}
You should also use onSubmit client script since user can click "Close Task" button to move task to close complete
function onSubmit() {
if (g_form.getValue('state') == '3' && g_form.getValue('variables.variableName') == '') {
g_form.setMandatory('variables.variableName', true);
return false;
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2025 08:20 AM
how do i specify for a certain catalog item only?