RITM must be closed-incomplete if any of its child SCTASKs are Closed-Incomplete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2025 06:59 AM
Hi Team can anyone help me achieving the requirement below
RITM can be closed-complete if all of its child SCTASKs are a combination of Closed-Complete
RITM must be closed-incomplete if any of its child SCTASKs are Closed-Incomplete
A RITM should not be able to be closed without its child SCTASKs being closed
Below script i have return but its not working for the second requirement and its over riding help me with script and it has to achieve only via script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2025 03:20 AM
@PatlalaShaR verify other business rules that trigger on state changes, especially those that set the state to "Closed Complete on sc_req_item table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2025 11:44 PM
can you try this
(function executeRule(current, previous /* null when async */) {
var ritmGR = new GlideRecord('sc_req_item');
if (!ritmGR.get(current.request_item)) {
gs.info('RITM not found for SCTASK {0}', current.number);
return;
}
var CLOSED_COMPLETE = 3;
var CLOSED_INCOMPLETE = 4;
var taskGR = new GlideRecord('sc_task');
taskGR.addQuery('request_item', ritmGR.sys_id);
taskGR.query();
var totalTasks = 0;
var closedTasks = 0;
var hasIncomplete = false;
while (taskGR.next()) {
totalTasks++;
if (!taskGR.active) closedTasks++;
if (taskGR.state == CLOSED_INCOMPLETE) hasIncomplete = true;
}
// Only proceed if ALL tasks are closed (inactive)
if (totalTasks > 0 && closedTasks === totalTasks) {
var newState;
if (hasIncomplete) {
newState = CLOSED_INCOMPLETE;
} else {
// Verify ALL tasks are Closed-Complete
taskGR.initialize();
taskGR.addQuery('request_item', ritmGR.sys_id);
taskGR.addQuery('state', '!=', CLOSED_COMPLETE);
taskGR.query();
newState = taskGR.hasNext() ? CLOSED_INCOMPLETE : CLOSED_COMPLETE;
}
if (ritmGR.state !== newState) {
ritmGR.state = newState;
ritmGR.update();
gs.info('RITM {0} updated to state {1}', [ritmGR.number, ritmGR.state.getDisplayValue()]);
}
} else {
gs.info('RITM {0} not updated: {1}/{2} tasks closed', [ritmGR.number, closedTasks, totalTasks]);
}
})(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
‎05-22-2025 11:51 PM
HI Ankur, Thanks for response but its still does the same as i mentioned above its over-riding the flow