When cancelling a request, what causes Tasks to close?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2015 07:43 AM
Hi Everyone,
When using the OOB Cancel UI Action on the sc_request, it cancels the Request, closes sc_req_items, closes, tasks, and cancels workflows. My question is, what code is specifically closing the sc_tasks?
I've been poking around for a bit, but I'm struggling to narrow it down.
Thanks,Scott
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2015 08:07 AM
Scott,
You can enable debug business rules to see which are running which are closing these.
There is a business rule on sc_request which is 'request closure' which cancels are RITM's associated to it.
Also, when RITM is cancelled there is a business rule on sc_req_item which is 'Close Tasks Due to Cancellations' which cancels the Tasks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2015 02:16 PM
Excuse me for being a little new to this, but I've always struggled with this troubleshooting. I never even thought to check the sc_req_item, but did and found the BR you mentioned. I also discovered we already had a personalized version created to update the state from 4 to 7. Then I realized the task in question is a child to the sc_request, not the sc_req_item, so this BR wouldn't apply. Through a bit of trial and error, I've discovered the two BR's required for the Cancel UI action to modify the state of the task are:
- Mark Request Closed on the sc_request table
- Cancel Workflows Upon Cancellation on the task table
I've disabled all other BR's on the sc_request, sc_req_item, sc_task, and task (except for the one that Can request be sourced, which I believe initiates the workflow that creates this task).
I'm confused about how these two BR's together cause the state of a task to change to 4 when the Cancel UI on the sc_request is used.
Mark Request Closed:
The last If statement seems to be the area affecting things.
if (current.request_state == "closed_complete" ||
current.request_state == "closed_incomplete" ||
current.request_state == 'closed_cancelled' ||
current.request_state == 'closed_rejected' ||
current.stage == "closed_complete" ||
current.stage == "closed_incomplete") {
current.active = false;
if (current.closed_by.nil())
current.closed_by = gs.getUserID();
if (current.closed_at.nil()) {
current.closed_at = gs.nowDateTime();
current.business_duration = gs.calDateDiff(current.opened_at.getDisplayValue(),current.closed_at.getDisplayValue(),false);
current.calendar_stc = gs.dateDiff(current.opened_at.getDisplayValue(),current.closed_at.getDisplayValue(),true);
}
if(current.state == 1) {
var state = current.request_state.indexOf('closed') == 0 ? current.request_state : current.stage;
switch(state + '') {
case 'closed_complete':
current.state = 3;
break;
default:
current.state = 4;
break;
}
}
}
Cancel Workflows Upon Cancellation:
/**
Service-now.com
Description: If task state changes to closed incomplete (4), cancel related workflows so we don't keep tasks active
**/
cancelMyWorkflows();
function cancelMyWorkflows() {
//get workflow helper
var workflow = new Workflow();
//cancel all my workflows
var numCnxd = workflow.cancel(current);
if (numCnxd > 1)
gs.addInfoMessage(numCnxd + " " + gs.getMessage("Workflows for {0} have been cancelled", current.getDisplayValue()));
else if (numCnxd == 1)
gs.addInfoMessage("1 " + gs.getMessage("Workflow for {0} has been cancelled", current.getDisplayValue()));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2016 11:15 PM
Hello Mani,
We have one requirement, when request is cancelled then its associated RITM and Task's state should also be set to Cancelled. But the thing is I am not able to find any code in Geneva instance which is changing the state of RITM.
Through cancel button I can change the state of Request. And for task's state change "Close Tasks Due to Cancellations" B rule can be updated as required. But for request it automatically moves to "Closed Incomplete" but don't know how. I got some B rule which must be the cause but still did not find function.
request item closure --> Business rule have below code
-------------------------------------------------------------------------------------------------------------------------------
// we just closed this requested item. Have to cancel its approvals
var reqItem = new SNC.RequestItem(current);
if (reqItem)
reqItem.cancelRelatedRecords(); --> I am not sure where this function comes from
-------------------------------------------------------------------------------------------------------------------------------
Please reply if you find any solution.
Sneha Gadawe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2016 02:04 AM
Hi Scott,
Did you finally understand what exactly caused changing tasks to "Closed Incomplete"?
Currently if i cancel RITM workflow --> child tasks become "Closed Incomplete".
And i don't understand why it's happened.
I've tried to disable
- Mark Request Closed on the sc_request table
- Cancel Workflows Upon Cancellation on the task table
but tasks still become "Closed Incomplete".
IF you found out root cause -> please share details.