Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How to trigger a workflow from a business rule?

poornima2
Mega Expert

How to trigger a workflow from a business rule?
Thanks

4 REPLIES 4

tyler_jones
ServiceNow Employee

If you look at the Business Rule titled Start Workflow (sc_req_item), it gives some hints.


startWorkflow(current.cat_item.workflow.toString());

function startWorkflow(id) {
var w = new Workflow();
var context = w.startFlow(id, current, current.operation(), getVars());
if (context != null)
current.context = context.sys_id;
}

/**
* Get the variables from the request item so that we can map these to the workflow.input
* variables if the names match.
*/
function getVars() {
var vars = {};
for (var n in current.variables)
vars[n] = current.variables[n];

return vars;
}


It looks like all it wants is this:



var w = new Workflow();
var context = w.startFlow(id, current, current.operation(), variable_map);


didn' t worked 

Hello @tyler_jones ,

As you suggested, i have used the below line,

Could you please tell me, how to use the "variable_map" in workflow.
var context = w.startFlow(id, current, current.operation(), variable_map);


For example:


var vars = { "number" : "5" }
var context = w.startFlow(id, current, current.operation(), vars); // passing vars obj to Workflow.


How to access the "number" property in Workflow, please suggest the syntax.

 

Thanks in Advance,
Hariharan N

Haviesh1
Kilo Explorer

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

var wflw = new Workflow();

wflw.startFlow(wflw.getWorkflowFromName('wf_name'), current, 'update');

})(current, previous);