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
07-01-2025 08:49 AM
@Jen11 if you are using UI policy, then in the condition builder you can specify the catalog item.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2025 10:42 AM - edited 07-01-2025 10:43 AM
Hi @Jen11 ,
Hope you're doing well!
You can add your catalog item condition on an UI policy on Catalog Task(sc_task) Table.
On the condition builder, select show related fields > Requested Item > Item to add filter for a specific catalog item.
Please refer to the attached screenshot, thank you!
Best Regards,
Sharif
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2025 10:16 PM
To run it only for particular catalog item do this
you can use a display business rule and get the catalog item name and store in g_scratchpad variable
Then use that in your onChange and onSubmit script
Display business rule: sc_task
Script:
g_scratchpad.catalogItemName = current.request_item.cat_item.name.toString();
Then use that in onChange and onSubmit
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (g_scratchpad.catalogItemName == 'Your Item Name Here') {
if (g_form.getValue('state') == '3' && g_form.getValue('variables.variableName') == '') {
g_form.setMandatory('variables.variableName', true);
}
}
}
function onSubmit() {
if (g_scratchpad.catalogItemName == 'Your Item Name Here') {
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
06-30-2025 08:17 PM - edited 06-30-2025 08:23 PM
Hi @Jen11
Use a UI policy to mandate the field based on specific conditions. Please find below a sample UI policy that makes the 'Short Description' field mandatory when the task state is set to 'Closed Complete'. This approach will cover both On Change and On Submit scenarios.
Regards,
Siva