Cancel existing WorkFlow and start process with new workflow
The following code block can be used to cancel the current workflow and start the process with the newly prepared workflow.
//Fonksiyon parametreleri: Kaydın tablo adı(table name), Kaydın sys_id'si(record sys_id), wf_workflow tablosunda ki work flow'un sys_id si(workflow sys_id). restartFlow('change_request','49ce936787fc5d54520e557bbbbb35e7', 'df3ea2701b8a2c508968a8217e4bcbf8'); function restartFlow(record_table,record_sys_id, wf_v_sys_id) { var gr = new GlideRecord(record_table); var q = 'sys_id=' + record_sys_id; gr.addEncodedQuery(q); gr.query(); if (gr.next()) { var oldWorkflow = new Workflow(); oldWorkflow.cancel(gr); var w = new Workflow(); var context = w.startFlow(wf_v_sys_id, gr, gr.update()); } }
Alternative:
var gr = new GlideRecord('sc_req_item'); gr.get('2632f478472611d403587d01e36d430f'); var workflow = new Workflow(); workflow.cancel(gr); var newWorkflow = new Workflow(); newWorkflow.startFlow(new Workflow().getWorkflowFromName('WF_NAME'), gr, '');