Cancel and restart workflow for Demand

vamshi krishna4
Giga Guru

Hi All,

Hope you are doing good.

I created a simple workflow for demand form, if its in qualified state the workflow will trigger the approvals and move it to next state if approved. But in demand form when Reset to Draft button is clicked the state chances to draft state.

Once the workflow is triggered in qualified state and then reset is draft button is clicked then i need to cancel the existing flow and restart the flow when it moves to qualified again.

I need some help in cancelling and restarting the workflow.

 

Thanks in advance.

Regards,

vamshi

1 ACCEPTED SOLUTION

MrMuhammad
Giga Sage

HI,

You can use workflow API to achieve this. 

Sample Script: You can use this in any server side script i.e. UI action, Business rule etc

var workflow = new Workflow();
      //cancel all the workflows, where current is a task record with a workflow context
      workflow.cancel(current);
      gs.addInfoMessage(gs.getMessage("Workflows for {0} have been cancelled", current.getDisplayValue()));

For detailed information please see API documention at:

cancelWorkflow() | Documentation

RestartWorkflow() | Documentation

Regards,

Muhammad

Regards,
Muhammad

View solution in original post

1 REPLY 1

MrMuhammad
Giga Sage

HI,

You can use workflow API to achieve this. 

Sample Script: You can use this in any server side script i.e. UI action, Business rule etc

var workflow = new Workflow();
      //cancel all the workflows, where current is a task record with a workflow context
      workflow.cancel(current);
      gs.addInfoMessage(gs.getMessage("Workflows for {0} have been cancelled", current.getDisplayValue()));

For detailed information please see API documention at:

cancelWorkflow() | Documentation

RestartWorkflow() | Documentation

Regards,

Muhammad

Regards,
Muhammad