How To call workflow from scheduled job
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2022 06:03 AM
Hi Team,
I have a requirement to call a workflow from a scheduled job and wanted to pass a group sys id to the workflow. Below is my script.
function triggerapproval() {
var temp = new GlideRecord('std_change_record_producer');
temp.addEncodedQuery('active=true');
temp.addEncodedQuery('u_number=123');
temp.query();
while (temp.next()) {
var grp = '<sys_id>';
var w = new Workflow();
var vars = {};
var context = w.startFlow('b85c9d111b3a5d10321f9759b04bcb79', temp, 'check template', null);
}
}
In the code, b85c9d111b3a5d10321f9759b04bcb79 is my workflow sys_id, temp is the object, check template is my workflow name.
The above code is not helping me to reach the workflow. Can anyone guide what is wrong and also how to pass the variable grp in the workflow calling.
Any help on this would be much appreciated.
Regards,
Manjushree

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2022 09:43 PM
Hello @Manju Shree
have you declared input in inputs section of the workflow? if not, then create a new input record in your workflow as shown below:
Once it is done, try below script in scheduled job:
function triggerapproval() {
var temp = new GlideRecord('std_change_record_producer');
temp.addEncodedQuery('active=true');
temp.addEncodedQuery('u_number=SCTMPL0001107');
temp.query();
while (temp.next()) {
var grp = '123';
var w = new Workflow();
var vars = {};
vars.NAME_OF_INPUT_DEFINED = grp; //replace name of input defined, ex:u_group in above pic
var context = w.startFlow('c07c51d11b3a5d10321f9759b04bcb1d', temp, 'update', vars);
}
}
triggerapproval();
and in run script activity of workflow:
gs.log('Inside Wf');
var groupval = workflow.inputs.NAME_OF_INPUT_DEFINED; //replace name of input defined, ex:u_group in above pic
gs.log(groupval+ ' grp value check');
Thanks,
Ali
Thank you,
Ali