Cancel and restart workflow

josh_brostoff
Giga Contributor

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;

7 REPLIES 7

larstange
Mega Sage

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


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.


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.


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.