How to pass variables from Business Rule to Workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2024 11:32 AM
Hi Team,
I have written the following piece of Business Rule to pass variables in Workflow.
var wf = new Workflow();
//Get the workflow id
var wfId = wf.getWorkflowFromName("SIC_Workflow_Work");
//Start workflow, passing along object containing name/value pairs mapping to inputs expected by the workflow
var vars ={};
vars.input_var_name1 = parsedData.result.short_description;
vars.input_var_name2 = parsedData.result.number;
// add as many variables as your workflow is expecting, then pass the object
var a ="Test 1";
var b ="Test 2";
wf.startFlow (wfId,null,"SIC_Workflow_Work",a,b);
//wf.startFlow (wfId,null,"SIC_Workflow_Work",vars);
The workflow is triggering but variables are not being passed. Here is my workflow script.
gs.log("saikat workflow triggered");
workflow.scratchpad.var1 =workflow.inputs.a;
workflow.scratchpad.var2 =workflow.inputs.b;
gs.log("saikat step 1"+workflow.scratchpad.var1+"format"+typeof workflow.scratchpad.var1);
gs.log("saikat step 2"+workflow.scratchpad.var2+"format"+typeof workflow.scratchpad.var2);
The first log message is printing but the scratchpad logs are appearing to be undefined. Seeking your expert opinion to read the variables passed from BR to Workflow. I made a lot of changes to achieve this so far but nothing worked.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2024 11:39 AM
Did you make sure to add the input variables to the workflow as well?
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2024 12:06 PM
Thanks for highlighting. I added it but still no help. Here is the updated script. "u_yet" and "u_met" are the input variable column names.
gs.log("saikat workflow triggered");
workflow.scratchpad.var1 =workflow.inputs.u_yet;
workflow.scratchpad.var2 =workflow.inputs.u_met;
gs.log("saikat step 1"+workflow.scratchpad.var1+"format"+typeof workflow.scratchpad.var1);
gs.log("saikat step 2"+workflow.scratchpad.var2+"format"+typeof workflow.scratchpad.var2);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2024 01:08 PM
This is what you should have had
var vars ={};
vars.u_yet = parsedData.result.short_description;
vars.u_met = parsedData.result.number;
// add as many variables as your workflow is expecting, then pass the object
wf.startFlow (wfId,null,"SIC_Workflow_Work",vars);
And then in workflow you can use it. Also I would suggest using gs.info instead of gs.log.
Please mark this response as correct or helpful if it assisted you with your question.