- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2025 02:40 AM
An attachment field variable is hidden in the catalog item view and only becomes visible in the Catalog Task. The fulfiller is expected to attach a file to this variable before setting the task to "Closed Complete."
While we can use a Catalog UI Policy to make the field mandatory, the problem is that the attachment variable becomes mandatory regardless of the task’s state. This prevents assigning a user to the Catalog Task, as the system requires the attachment before updating the record.
How can we configure it so that the attachment variable is only mandatory when the Catalog Task state is set to "Closed Complete"?
To clarify, I want to apply a behavior where the mandatory requirement of the catalog item's attachment variable is enforced only when the Catalog Task’s state is "Closed Complete." The attachment variable is hidden from catalog item view.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2025 02:58 AM
Hi @symonflores_23
You can achieve this via either client acript or UI policy in the catalog task (sc_task) table.
UI policy sample:
Modify the highlighted variable name as required.
Regards
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2025 02:48 AM
Hi @symonflores_23 ,
the screenshots that you have pasted are not visible
you can create an onChange client script on sc_task table on State field
and when new value is close complete set the variable mandatory
if(newValue = ="close_complete choice backend value")
g_form.setMandatory('your_attachment_variable_name',true)
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2025 02:50 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2025 02:57 AM
3 ways to handle
1) normal onChange client script on state field of sc_task and check if state is closed complete then make those mandatory
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue == '3') {
if (g_form.getValue('variables.variableName1') == '')
g_form.setMandatory('variables.variableName1', true);
}
}
2) You need to ensure this is handled via the OOTB Close Task UI action as well as user can close the task from button as well
function closeTask() {
g_form.setValue('state', 3);
//Call the UI Action and skip the 'onclick' function
if (g_form.getValue('variables.variableName1') == '') {
g_form.setMandatory('variables.variableName1', true);
return;
}
gsftSubmit(null, g_form.getFormElement(), 'close_sc_task');
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
updateTask();
function updateTask() {
current.state = 3;
current.update();
}
3) before update business rule on sc_task table
State Changes to Close Complete && current.request_item.cat_item.name == 'Your Item Name'
Script:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
if (current.variables.variableName == '') {
current.setAbortAction(true);
gs.addErrorMessage('Please add file before closing task');
}
})(current, previous);
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-27-2025 08:05 PM
Thank you for marking my response as helpful.
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