How to trigger/start Workflow from before/after business rule script

pratap1
Giga Contributor

Hi All

I created a workflow named "CheckDocumentCompletedForSurgery".

now i want to trigger/start this workflow from business.

(function executeRule(current, previous /*null when async*/) {

// Add your code here.

})(current, previous);

what should i write in executeRule function so that my workflow get triggered.

Please help me. I am new to ServiceNow.

Thanks in Advance.

Best regards,

Pratap Ranawat

1 ACCEPTED SOLUTION

snehabinani26
Tera Guru

Hi Pratap,



(function executeRule(current, previous /*null when async*/) {


// This business Rule will trigger Breakfix Return Workflow when State changes from In Use to In Maintenance


var wflw = new Workflow();


wflw.startFlow(wflw.getWorkflowFromName('give the workflow name'), current, 'update');


})(current, previous);


View solution in original post

7 REPLIES 7

I was searching for an answer to something slightly related and found the answer at:

 

https://community.servicenow.com/community?id=community_question&sys_id=57258b6ddbd8dbc01dcaf3231f96190f

 

Chuck's answer is to make sure you are calling the global scope of workflow. Try changing the "new Workflow()" to new global.Workflow()

Hi Sneha ,

Can you pls explain about the arguments current,'update' use in the below line

wflw.startFlow(wflw.getWorkflowFromName('give the workflow name'), current, 'update');

Thank you in advance,

Sweety

 

Haviesh1
Kilo Explorer

Not working for me