How to cancel a specific workflow with bussines rule?

Nayara Araujo
Tera Contributor

Hi All,

 

How can I cancel a specific workflow with bussines rule?

 

Workflow Start Condition: When incident state changed to pending.

 

How can I cancel this specific workflow with a business rule if the same incident state changes to in progress again? Without impacting other flows.

 

I hope that someone can help me with this.

 

Thank you in advance.

1 ACCEPTED SOLUTION

Devender Kumar
Tera Guru
Tera Guru

Hi @Nayara Araujo 

 

You can find the solution in the ‘Workflow’ script include by way of the ‘getRunningFlows’ and ‘cancelContext’ functions. The following script could be run from a business rule, UI action, or even within a ‘Run Script’ workflow activity. The example given here cancels any ‘Routine Change’ workflow contexts associated with the ‘current’ record.

 

Business rule condition : State changes from pending

 

 

 

//Query for all executing workflow contexts
var flows = new Workflow().getRunningFlows(current);
while(flows.next()){
//Check for associated workflows by name
if(flows.workflow_version.getDisplayValue() == 'Routine Change'){
//Cancel the workflow context
new Workflow().cancelContext(flows);
}
}

 

 

  

 

If my answer resolved your issue the don't forget to mark correct or helpful.

 

Regards

Devender

View solution in original post

1 REPLY 1

Devender Kumar
Tera Guru
Tera Guru

Hi @Nayara Araujo 

 

You can find the solution in the ‘Workflow’ script include by way of the ‘getRunningFlows’ and ‘cancelContext’ functions. The following script could be run from a business rule, UI action, or even within a ‘Run Script’ workflow activity. The example given here cancels any ‘Routine Change’ workflow contexts associated with the ‘current’ record.

 

Business rule condition : State changes from pending

 

 

 

//Query for all executing workflow contexts
var flows = new Workflow().getRunningFlows(current);
while(flows.next()){
//Check for associated workflows by name
if(flows.workflow_version.getDisplayValue() == 'Routine Change'){
//Cancel the workflow context
new Workflow().cancelContext(flows);
}
}

 

 

  

 

If my answer resolved your issue the don't forget to mark correct or helpful.

 

Regards

Devender