How to cancel workflow correctly via UI action?

Zod
Giga Guru

Hi,

a UI action should cancel a workflow ... as well as all approvals.


Somehow the cancelation of the approvels went fine .. but the "old" workflow is still active and goes ahead when restating the process.

Could you please check what is wrong here?

****

function clickedCancel(){

  if(confirm('SURE?')){   //Call the UI Action and skip the 'onclick' function

  gsftSubmit(null, g_form.getFormElement(), 'cancel_xxx');           //MUST call the 'Action name' set in this UI Action

  }

  return false;

}

// Server side code

if(typeof window == 'undefined')

  cancelXXX();

function cancelXXX(){

  current.u_field= '123';

  current.update();

  gs.addInfoMessage(gs.getMessage("Message"));

// cancel approval workflows

  var wf = new Workflow();

  wf.cancel(current);

  new WorkflowApprovalUtils().cancelAll(current);

  new Workflow().restartWorkflow(current);

  //cancel workflow

      var oldWorkflow = new Workflow();

      oldWorkflow.cancel(current);

}

1 ACCEPTED SOLUTION

Karthik Reddy T
Kilo Sage

Refer the below thread may helpful to you.



UI Action Cancel Workflow


Karthik Reddy T.
ServiceNow Commnunity MVP -2018 class.

View solution in original post

5 REPLIES 5

Karthik Reddy T
Kilo Sage

Refer the below thread may helpful to you.



UI Action Cancel Workflow


Karthik Reddy T.
ServiceNow Commnunity MVP -2018 class.

YES! Thank you.


Zod
Giga Guru

Like this all works fine ...



function clickedCancel(){


  if(confirm('SURE?')){   //Call the UI Action and skip the 'onclick' function


  gsftSubmit(null, g_form.getFormElement(), 'cancel_xxx); //MUST call the 'Action name' set in this UI Action


  }


  return false;


}




// Server side code


if(typeof window == 'undefined')


  cancelXXX();




function cancelService(){


  // delete workflow


  new Workflow().deleteWorkflow(current);



  current.u_field= '123';


  current.update();


  gs.addInfoMessage(gs.getMessage("Message"));


  // cancel approval workflows


  var wf = new Workflow();


  wf.cancel(current);


      new WorkflowApprovalUtils().cancelAll(current);


  new Workflow().restartWorkflow(current);



}


Still strange ... when restarting the WF after the Workflow was changed ... the "old version" is taken ...