Help with an issue where workflow tasks are open and RITM is close complete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 04:01 PM
Business rule is closing RITM State=close complete even though another task is created with using workflow. I'm looking for a script to not close the RITM until all task from workflow and even an ad hoc tasks are closed. Then once all tasks are close completed then I need the RITM state = close complete and stage = completed/
Any help is greatly apprciated.
(function executeRule(current, previous /*null when async*/) {
// Query to check if there are any open sc_tasks for the current ritm
var task = new GlideRecord('sc_task');
task.addQuery('request_item', current.request_item);
task.addQuery('active', true);
task.query();
var hasActiveTasks = false;
// Check if there are any active tasks
while (task.next()) {
hasActiveTasks = true;
break;
}
if (!hasActiveTasks) {
var ritm = new GlideRecord('sc_req_item');
if (ritm.get(current.request_item)) {
// Query to check if there are any active tasks remaining for the current ritm
var remainingTasks = new GlideRecord('sc_task');
remainingTasks.addQuery('request_item', current.request_item);
remainingTasks.addQuery('active', true);
remainingTasks.query();
var activeTaskCount = 0;
while (remainingTasks.next()) {
activeTaskCount++;
}
// If no active tasks are remaining, close the ritm
if (activeTaskCount === 0) {
ritm.state = 3; // Closed state
ritm.update();
}
}
}
})(current, previous);