How to cancel the RITM, when one of its task is close cancelled?

Sheenu Mejo
Mega Contributor

I need to close the whole RITM and tasks when one of its tasks assigned to a specific group is close canceled.

Please put up your suggestions here.

1 ACCEPTED SOLUTION

Thanks a lot for your replies and responses Brad. As you said, yeah it worked for me. I used the following script in my "wait for condition" activity.

answer = true;
workflow.scratchpad.flag = false;
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.sys_id);
gr.query();

var state;
var group;

while (gr.next()) {

state = gr.getValue('state');
group = gr.getDisplayValue('assignment_group');

if (group.startsWith("HR") && (state == 7)) {
workflow.scratchpad.flag = true;
answer = true;
break;
} else if (!((state == 3) || (state == 4) || (state == 7))) {

answer = false;

}
}

View solution in original post

14 REPLIES 14

Now the workflow entering to if activity after all tasks have been complete, incomplete, or skipped

In my OOB PDI I have this code in an If activity.  When I close any task Closed Incomplete (4) it follows the Yes path, and when I close all tasks Complete (3) or Skiped (7) it follows the No path

answer = ifScript();

function ifScript() {
var result = 'no';
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.sys_id); //returns all of the tasks for the current RITM
gr.query();
while(gr.next()){
var state = gr.getValue('state');
if(state == 4){
result = 'yes';
}
}
return result;
}

So what is happening for you when it doesn't work - it is always resolving to No even when a task is Closed Incomplete, or it is always resolving to Yes even when no tasks are Closed Incomplete, or ...?

If one task is close completed then it is taking that path in if activity. It is not considering other tasks.

In my mockup I am now also creating tasks with a script, and added your wait for script.  When I close one task complete and one task incomplete it is correctly following the Yes path, and when I close both tasks complete it is correctly following the No path.  Note that my script is opposite from your original one.  My If condition is 'a task is closed incomplete' so the answer Yes means we should go to the incomplete path.  If this still isn't working right for you, please post a screenshot of your current workflow and If script.  Also be sure you are testing with newly-submitted requests as workflow changes do not take effect on previously-submitted requests.

Thanks a lot for your replies and responses Brad. As you said, yeah it worked for me. I used the following script in my "wait for condition" activity.

answer = true;
workflow.scratchpad.flag = false;
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.sys_id);
gr.query();

var state;
var group;

while (gr.next()) {

state = gr.getValue('state');
group = gr.getDisplayValue('assignment_group');

if (group.startsWith("HR") && (state == 7)) {
workflow.scratchpad.flag = true;
answer = true;
break;
} else if (!((state == 3) || (state == 4) || (state == 7))) {

answer = false;

}
}