Amit Gujarathi
Giga Sage
Giga Sage

Hi All,

Hope you are doing fine.

In todays article we will see how we can cancel the workflow.

 

Symptoms

Reacently I came accross one request from the process to cancel/close all the Change request which were not acted upon for last 2 years . As a part of this requirement we wrote a fix script which will close/cancel all the change request.

But guess what thats not the happy ending we were looking for , we found out that we have closed/cancel the changes but the workflow associated with it is still active. We have to cancel the active workflow for this changes as the change is closed.

So in this article we will see how we can cancel the workflow attached to record.

 

Diagnosis

The solution of this requirement is to cancel all the active workflow which were attached to the closed / canceled changes.

For this we have to use the Workflow API.

 

Solution

Please find the script to cancel the active workflow context.

var changeSysID = '3e61e74e871655d0822e8667cebb359c'; // Change request Sys_id

var grChange = new GlideRecord('change_request');
grChange.get(changeSysID);

var grWorkflowContext = new GlideRecord('wf_context'); //Get the context of the workflow for given change request
grWorkflowContext.addQuery('id',grChange.getUniqueValue());
grWorkflowContext.addQuery('workflow_version','588f82b5879211d0822e8667cebb3578'); //Query with the active workflow version
grWorkflowContext.query();
if (grWorkflowContext.next()) {

	var workflow = new workflow();
	workflow.cancelContext(grWorkflowContext);

}

 

Please mark Correct / Helpful if you find it useful.

 

Regards,

Amit Gujarathi

Version history
Last update:
‎10-13-2022 02:30 AM
Updated by:
Contributors