How to call a sub-workflow from within a workflow

ritaaudi
Tera Contributor

Hi: I'm creating a service catalog to assign assignment groups to a user. I want to have the main workflow call a sub-workflow that will update the user record with one assignment group each time. So the main workflow will have the user record and all assignment groups and will pass the user with only one assignment group to the sub-workflow. Can this be done?

Appreciate your advice! Rita

15 REPLIES 15

ritaaudi
Tera Contributor

Hi Chuck and Julian: The reason is each group has a notification and approval activity before the user is added to the group. The group manager will approve or reject. So I want to call the subflow for each group to get the approval and add the user record to the group. One group manager might approve access, another might reject. The user will end up getting only the assignment groups that got approved.


Does a workflow have a name that can be called from within a script?


Thank you both!


Look at the workflow script include


you can use that to cancel, delete add start, restart etc



var wfwvgr = new GlideRecord('wf_workflow_version');


if (wfwvgr.get('name','MyWorkFlow'))


      wf.startFlow(wfwvgr.workflow, current, 'update','');



the last option is vars, so you can pass some on


Midhun1
Giga Guru

Hi Ruti,



For defining inputs to create sub-flows you need to active this property glide.workflow.enable_input_variables.


ritaaudi
Tera Contributor

Hi everyone:


I also found the following on the wiki:


var w = new Workflow();


var context = w.startFlow(id, current, current.operation(), getVars());



For the getVars(), do I replace that with the variables comma separated? Such as "usr, grp"?


Do I have to activate glide.workflow.enable_input_variablesif I'm just passing the variables in the startFlow?


Thank you all.


Not sure as I have only ever called sub workflows from a workflow and passed te data as needed.   I guess the setting that Midhun has mentioned is in the more recent versions.   Never had to use that in older versions and not had a reason to pass paramaters to recent subflows to know.



Where I have used the workflow script include to process workflows, they are typically running of data from the record so I have not had to pass variables.


If no one on here can help and the wiki does look a little barren on this,   I'd look to create a new WF that just simply sends you a quick notification which sends you the vaue of some variables


try attaching the WF to a ticket passing some variables and see if your notification sends you the data (aka, the variables you passed) as expected.



Be interested to see the results if you do try this.


I may have a look at some stage, but I do not want ot commit as a few issues at home are stopping me from planning too many things at the moment