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

I was trying to restart a request item workflow.   This business rule seems to be just for the change request table.


Did you get this working?


Mo27
Kilo Expert

Hi Josh, did you find a solution to this? I am also trying to also restart one workflow in a situation where there is 2 assigned to a change request both in cancel state. 

Thanks