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

Chuck Tomasi
Tera Patron

Hi Rita,



You can use the workflow.scratchpad object to pass information to the subflow.



My initial question is how do you know which assignment group to use if you have ALL assignment groups and want to call the subflow with just one? Are you looking to call the subflow for each assignment group in the list you have somehow compiled?



Using the Workflow Scratchpad - ServiceNow Wiki


Using Subflows - ServiceNow Wiki


Hi Chuck: So what I want to do in the main workflow is have a for loop in a 'wait for condition' activity. Something like:


var user = current.variables.caller_id;


var assignment_groups = current.variables.assignment_groups;


//note variables.assignment_groups is a List Collector category item variable


for (var i = 0; i<assignment_groups.length; i++){


    var group = assignment_groups[i];


    workflow.scratchpad.ag = group;


    workflow.scratchpad.usr = user;


// now how to I call the subflow here?


 


}


Thank you!!


Hi Rita,



Not sure using that approach. Is it possible to pass all groups and let the subflow deal with the parsing/looping?


poyntzj
Kilo Sage

Why in a sub workflow and not just via a quick script and a loop ?


Sub workflows is easy. but seems unusual to me.