- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2017 12:24 PM
Hello all,
I have a RUN SCRIPT that creates multiple tasks based on a list collector but after it creates the tasks the workflow continues and closes the RITM. I need the RITM to stay open until all of the SCTASK have been closed.
I have tried using this script with a 'Wait for Condition' and while it does stop the RITM from closing, once all the SCTASK have been closed the RITM stay's open.
//Query for all tasks to see if they are inactive
var rec = new GlideRecord('sc_task');
rec.addQuery('request_item', current.sys_id);
rec.addQuery('active', true);
rec.query();
if(rec.hasNext()){
answer = false;
}
else{
//Continue
answer = true;
}
Thank you for any help!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2017 12:32 PM
This is likely caused by the fact that the catalog tasks' closure is not triggering the workflow to continue running. What you'll need to do is create a business rule on the catalog task that triggers the RITM's workflow when the task is closed. That script will look something like this:
var ritmRec = new GlideRecord('sc_req_item');
if(ritmRec.get(current.request_item)) {
new Workflow().broadcastEventToCurrentsContexts(ritmRec, 'update', null);
}
PS - this BR on the catalog task table should be an after BR as it is interacting with another table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2017 12:32 PM
This is likely caused by the fact that the catalog tasks' closure is not triggering the workflow to continue running. What you'll need to do is create a business rule on the catalog task that triggers the RITM's workflow when the task is closed. That script will look something like this:
var ritmRec = new GlideRecord('sc_req_item');
if(ritmRec.get(current.request_item)) {
new Workflow().broadcastEventToCurrentsContexts(ritmRec, 'update', null);
}
PS - this BR on the catalog task table should be an after BR as it is interacting with another table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2017 12:46 PM
Adam,
Turns out we had a business rule for it and I just had to add my Order Guide to it. Thanks for the help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-22-2018 08:12 AM
Hi Jacob,
I have a similar situation, have tried creating after business rule but it's not working.
Thanks in advance for your help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-22-2018 08:41 AM
Hello,
What we have in our instance is a business rule that runs after insert or update and has the following filter:
State = closed complete OR closed Incomplete OR closed skipped
AND
Order Guide = our onboarding order guide
Then we run this script:
(function executeRule(current, previous /*null when async*/) {
//Create query for tasks in an open state
var updateRecords = true;
//Query for open tasks with the same parent RITM
var scTask = new GlideRecord('sc_task');
var scQry1 = scTask.addQuery('request_item', current.request_item);
var scQry2 = scTask.addQuery('state', -5);
scQry2.addOrCondition('state', 1);
scQry2.addOrCondition('state', 2);
scTask.query();
while (scTask.next()) { updateRecords = false; gs.log('there are other open tasks');}
if (updateRecords) { gs.log('no open tasks');
//If there are no other open tasks for the RITM, update the RITM
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('sys_id', current.request_item);
ritm.query();
while (ritm.next()) {
ritm.state = current.state;
ritm.stage = 'complete';
ritm.comments = '**This is an automated message**' + '\n' + 'The Request Item state is ' + current.state.getDisplayValue() + ', the last task has been closed';
ritm.update();
}
//Then update the REQ
var reqState = 'requested';
var req = new GlideRecord('sc_request');
req.addQuery('sys_id', current.request);
req.query();
while (req.next()) {
switch (current.state) {
case 3: reqState = 'closed_complete'; break;
case 4: reqState = 'closed_incomplete'; break;
case 7: reqState = 'closed_incomplete'; }
req.request_state = reqState;
req.update();
}
}
gs.log('script fired');
})(current, previous);