- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2023 01:46 PM
I created this business rule below. I'm using workflow that is creating additional SCTASKS. Then I create an ad hoc SCTASK (which is not in workflow) and if all the workflow SCTASKS are closed and the last ad hoc task is closed it does not close the RITM. Any idea how to get even ad hoc tasks to close the RITM if it's not in the workflow?
==========================BUSINESS RULES============================
Table - Catalog Task (sc_task)
When to Run - After Update
Condition - State is One of Closed States
Script -
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var sct = new GlideRecord('sc_task');
sct.addQuery('request_item', current.request_item);
sct.query();
var totalCount = sct.getRowCount();
var sct1 = new GlideRecord('sc_task');
sct1.addQuery('state', IN, '3,4,7');
sct1.addQuery('request_item', current.request_item);
sct1.query();
var completedtotalcount = sct1.getRowCount();
if (totalCount == completedtotalcount) {
var ritm = current.request_item.getRefRecord();
ritm.state = 3;
ritm.update();
}
})(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2023 01:47 PM
Hi @Julie Catano can you please give a try with below script
(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);
Please mark it Correct and Hit Like if you find this helpful!
Regards,
Eswar Chappa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 10:10 AM
I added the latest code and then also had to run this BR too. See below
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 10:10 AM
I added the latest code and then also had to run this BR too. See below