How to restrict the assignee to close one of the sc tasks in catalog item without an attachment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2024 11:40 PM
Hello Folks,
I've a catalog item which will generate 6 SC tasks. For one of the SC task, user should not be able to close the SC task without an attachment. How can I proceed with the solution on this. Help me to provide any scrips.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2024 12:01 AM
Hi,
Check below link that might help you.
Thanks,
Dhananjay.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2024 12:01 AM
If that one sc task has uniques short description then you can write before update business rule on sc task below is the sample script:
(function executeRule(current, previous /*null when async*/) {
// Define the unique short description for the SC task that requires an attachment
var uniqueShortDescription = "Unique Description"; // Replace with the actual unique short description
// Check if the current SC task is in the "Closed" state
if (current.state == '6') { // '6' represents the 'Closed' state in ServiceNow
// Check if the SC task has the unique short description
if (current.short_description == uniqueShortDescription) {
// Check if the SC task has an attachment
if (current.attachment.nil()) {
// If there is no attachment, prevent the SC task from being closed
gs.addErrorMessage('You cannot close this task without attaching a file.');
current.state = previous.state; // Rollback the state change
current.setAbortAction(true); // Prevent the record from being saved
}
}
}
})(current, previous);
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2024 12:16 AM
Hi @Avee90 ,
I tried your problem in my PDI and it works for me please refer below steps
1. Create Before Business rule, add table - Catalog Task (sc_task) and add appropriate filter condition
In Advance Section
Add below script
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
gs.log('BR Called = ' + current.getTableName());
var att = new GlideAggregate('sys_attachment');
att.addAggregate('COUNT');
att.addQuery('table_name', current.getTableName());
att.addQuery('table_sys_id', current.sys_id);
att.query();
var count = 0;
if (att.next()) {
count = att.getAggregate('COUNT');
if (count < 1) {
gs.addInfoMessage("Please attach Attachment");
current.setAbortAction(true);
}
}
})(current, previous);
Here's Result
Please mark my answer correct and helpful if it works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2024 02:13 AM
Hello Sarthak,
Thanks for your response. I tried BR, I'm getting the error message but the sc task is closing.