start/stop workflow

Shaik22
Tera Expert

Hello,

 

How to start,stop and cancel a workflow from script.

1 ACCEPTED SOLUTION

Manisha Reddy K
Mega Guru

Hello @Shaik22 ,

       Please find below the script for starting and cancelling the workflow.

1) Start the workflow

 

var gr = new GlideRecord('your_table');

gr.initialize();

gr.insert();

var wflw = new Workflow();
wflw.startFlow(wflw.getWorkflowFromName('give the workflow name'), gr, 'insert');

 

 2) Stop/Cancel the workflow

 

var workflow = new Workflow(); //cancel all the workflows, where current is a task record with a workflow context

workflow.cancel(current);

gs.addInfoMessage(gs.getMessage("Workflows for {0} have been cancelled", current.getDisplayValue()));

 

Mark this as helpful if it is

View solution in original post

2 REPLIES 2

Manisha Reddy K
Mega Guru

Hello @Shaik22 ,

       Please find below the script for starting and cancelling the workflow.

1) Start the workflow

 

var gr = new GlideRecord('your_table');

gr.initialize();

gr.insert();

var wflw = new Workflow();
wflw.startFlow(wflw.getWorkflowFromName('give the workflow name'), gr, 'insert');

 

 2) Stop/Cancel the workflow

 

var workflow = new Workflow(); //cancel all the workflows, where current is a task record with a workflow context

workflow.cancel(current);

gs.addInfoMessage(gs.getMessage("Workflows for {0} have been cancelled", current.getDisplayValue()));

 

Mark this as helpful if it is

Sagar Pagar
Tera Patron

Hi @Shaik22,

 

Take a look at ServiceNow product to start, cancel or stop the workflow using scripts.

Workflow - Global 

Workflow - developer site 

 

If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow