start workflow from Business rule and pass values to workflow

manojn_cse
Tera Contributor

Hi Team,
I am trying to trigger workflow from Business rule and pass values to workflow variable from Business rule. I used the syntax from below link . Workflow got triggered successfully but values are not getting assigned to workflow variables.

Ref URL : https://docs.servicenow.com/bundle/jakarta-servicenow-platform/page/administer/using-workflows/concept/c_UsingVariablesInAWorkflow.html#ariaid-title3

Business Rule on sc_req_item table :


startWorkflow(current.cat_item.workflow);
action.setRedirectURL(current);

function startWorkflow(id) {
gs.addInfoMessage("G U_SCCM_Device :"+current.u_sccm_device);
var w = new Workflow();
var vars = { } ;
vars.device = "ggg123" ;
vars.install_user_group = "input_var_value2" ;
vars.g_dev_1 = "test124" ;
//var context = w.startFlow(id, current, current.operation('update'),{device: "test124" });
//var context = w.startFlow(id, current, current.operation('update'),{g_dev_1: "g_dev_124" });
var context = w.startFlow(id, current, current.operation('update'),vars);
//var context = w.startFlow(id, current, current.operation('update'), getVars());
if (context != null)
current.context = context.sys_id;
//gs.addInfoMessage("GGG Inside Business Rule 123 :"+context);
gs.addInfoMessage("GGG getVars() :"+ getVars());
}


/**
* 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 = {};
vars.device = "ggg123";
vars.g_dev_1 ="g_test1234";

// gs.addInfoMessage("GGG vars.device:"+ vars.device);
// for (var n in current.variables)
//vars[n] = current.variables[n];

return vars;
}

Regards,
Manoj Nagarajan

1 ACCEPTED SOLUTION

havikosuru
Kilo Expert

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

gs.addInfoMessage("Business Rule started for Ping Host");

gs.log('workflow started for Failed Ping Events');

var wflw = new Workflow();


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

})(current, previous);

View solution in original post

5 REPLIES 5

havikosuru
Kilo Expert

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

gs.addInfoMessage("Business Rule started for Ping Host");

gs.log('workflow started for Failed Ping Events');

var wflw = new Workflow();


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

})(current, previous);

AshleyD13
Kilo Contributor

simply create an event and call it from BR.

how to call event from BR??

Kevin179
Kilo Expert

How are you trying to access the variables from within the workflow? Have the variables been defined in the workflow you are trying to use?

 

Also, have you seen this article that was linked to from the page you listed? It might prove useful.

https://docs.servicenow.com/bundle/jakarta-servicenow-platform/page/administer/using-workflows/concept/c_WorkflowCatalogVariables.html