Cancel and restart workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2017 02:49 PM
I have created a script to cancel and restart a workflow since I can seem to find a way to restart a workflow without canceling all running workflows for a current record. This script is canceling the current workflow, but not creating a new one. What is wrong here? pradeepksharma any ideas?
//If planned start date changes, then restart the workflow
if (current.start_date.changes()) {
//Query for all executing workflow contexts
var vFlows = new Workflow().getRunningFlows(current);
while(vFlows.next()){
//Check for the "Slack Change Pending Approval" workflow
if(vFlows.workflow_version.getDisplayValue() == 'Slack Change Pending Approval'){
//Cancel the workflow context
new Workflow().cancelContext(vFlows);
}
}}
var w = new Workflow();
var context = w.startFlow('1267b983136c72404562b0322244b05b', current, current.operation(), getVars());
function getVars() {
var vars = {};
for (var n in current.variables)
vars[n] = current.variables[n];
return vars;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2017 12:28 AM
Hi
The following two lines should be enough
new WorkflowApprovalUtils().cancelAll(current, comment);
new Workflow().restartWorkflow(current);
Its taken from the OOB business rule "SNC Approval - Reset conditions" on the change_request table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2017 05:59 AM
Hey Lars - it looks like the lines you mentioned will restart all workflows associated with the record. I only want to restart one specific workflow.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2017 02:37 PM
when i execute this, it throws 'cannot convert null to an object error'
in place of the current object, i am using the gr GlideRecord object.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2017 06:22 PM
There's an inactive business rule that comes out of the box named: SNC Approval - Reset conditions
The business rule contains details on how it works and options for handling previous approvals.