
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2014 06:14 AM
I'm looking for the best way to handle cancelling tasks automatically, if the requested item is cancelled or rejected after being approved. For example, if an Offboarding (employee termination) request is entered and approved, and then the employee decides to stay. Currently the manager, changes the request state from Approved to Cancelled, but the tasks were already created from the workflow. We've been manually cancelling the associated tasks. The workflow is still active, until all of the access has been granted (catalog tasks completed). I had thought about creating a script activity in the workflows, but I haven't been able to find an appropriate place for it with our current flow. Is there a better way (business practice) or automated way to accomplish this?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2014 08:01 AM
In order to cancel all associated tasks once the requested item is closed, you would want an after update business rule on the sc_req_item table that runs when the state changes to cancelled. You would want to query all records on the task table where the request_item is the current request_item and iterate through and close and update them.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2014 08:01 AM
In order to cancel all associated tasks once the requested item is closed, you would want an after update business rule on the sc_req_item table that runs when the state changes to cancelled. You would want to query all records on the task table where the request_item is the current request_item and iterate through and close and update them.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2014 08:49 AM
Thank you! I had thought about that after I posted this question, walked away and thought about it in different mindset (not workflow).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2015 12:56 PM
Hi Susan,
Were you able to create a business rule for this? If so, do you mind posting how you set up that biz rule and what the script entailed.
Thanks!
Niccole

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2015 06:33 AM
Hi Niccole,
Yes, I was able to implement a business rule to accomplish what we wound up needing. Since the "State" field is not visible on the request, managers wanted to change the "Approval" from approved to rejected instead (which probably is not ideal, but what we implemented for the immediate need).
Table: sc_req_item (select Advanced to enter script)
When: after (select Update)
Condition: current.approval.changesTo('rejected')
Script:
//Update RITM and comments
RITMUpdate();
function RITMUpdate() {
current.state = 6;
current.update();
}
//If RITM changes to Rejected, the child TASKS will be set to "Cancelled", unless they are completed already.
abortKids();
function abortKids() {
if (current.sys_id == '')
return;
var kids = new GlideRecord('sc_task');
kids.addQuery('parent', current.sys_id);
kids.query();
while (kids.next()) {
//If child task is set as complete: 1) Add message at top of RITM record 2) Update Work Notes on TASK 3) Resets state of TASK to Open
if (kids.state == 4) {
gs.addInfoMessage("You have tasks that have already been completed for this request, which should be addressed");
kids.work_notes = "Your task has been re-opened, because the parent Request was rejected after completion of your work. Please confirm if any of the work should be reversed for this request. Once the work is complete, please set the State as Complete.";
kids.state = 1;
kids.update();}
else {
kids.state = 6;
kids.work_notes="This task has been Cancelled, because the parent Request has been rejected";
kids.update();}
}
}