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

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);


Hi Sneha,



I am getting this error


Error Message


Workflow undefined, maybe missing global qualifier



while using above code. what could be possible reason?



Thanks,




Best regards,


Pratap Ranawat


Are you providing the correct Workflow name


Yes, i am providing right name.



Workflow name is


captureofworkflow.png



And my business rule script is


capturebusinessrule.png



What could be possible reason for error?






Thanks,



Best regards,


Pratap Ranawat