- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2024 11:09 AM
What i am missing?
(function executeRule(current, previous /*null when async*/) {
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 01:05 PM
i actually found that the script was taking in consideration when there were more than 1 task. so i update to script to:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2024 08:18 PM
the BR should be before update on sc_task
Condition: State [IS ONE OF] Closed Complete, Close Incomplete, Close Skipped
Script:
(function executeRule(current, previous /*null when async*/ ) {
// Query to get all active tasks related to the current request item
var scTask = new GlideRecord('sc_task');
scTask.addEncodedQuery('stateIN-5,1,2'); // Only active tasks
scTask.addQuery('request_item', current.sys_id); // Tasks related to this request item
scTask.setLimit(1);
scTask.query();
// Check if there are any active tasks
if (scTask.hasNext()) {
// Add error message and prevent closing of request item
gs.addErrorMessage('Request Item cannot be closed until all related Tasks are closed.');
current.setAbortAction(true); // Prevent the current record from being updated
}
})(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
12-31-2024 08:20 PM
your script is correct and the behavior is also OOB
when BR aborts it shows message and shows the same state value since it didn't allow the update in database.
User need to reload the record to see that the state has not changed
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
12-31-2024 08:22 PM
try this once
(function executeRule(current, previous /*null when async*/) {
// Query to get all active tasks related to the current request item
var scTask = new GlideRecord('sc_task');
scTask.addActiveQuery(); // Only active tasks
scTask.addQuery('request_item', current.sys_id); // Tasks related to this request item
scTask.query();
// Check if there are any active tasks
if (scTask.hasNext()) {
// Add error message and prevent closing of request item
gs.addErrorMessage('Request Item cannot be closed until all related Tasks are closed.');
current.setAbortAction(true); // Prevent the current record from being updated
current.state = previous.state;
}
})(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
01-02-2025 09:45 PM
Hope you are doing good.
Did my reply answer your question?
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