Workflow Coordinator Object - What it is and how to use it in Parallel flow launcher workflow activity to dynamically call multiple subflows based on a condition
Hello All,
A WorkflowCoordinator object specifies which subflows to run and the input variables to pass to those subflows.
Just thought to share this information which i did in one of my recent implementations. I had a requirement where i have a MRVS(Multi row variable set) on a catalog item which has three fields and on the selection of two fields, there exists a combination in the backend table which specifies which subflow to run and the two fields will be the inputs to that workflow(Subflow)
Below is the script with comments :
//Script from my parallel flow launcher activity...
javascript: //should start with javascript:
var details = JSON.parse(current.variables.u_fill_in_your_request);//parsing my MRVS
coordinator = new WorkflowCoordinator( {workflow:'User Access to AD Group'} );//Initializing my workflow coordinator object with my workflow name to run***
for(var i = 0 ; i< details.length;i++){//traversing my MRVS to check and prepare the inputs to my about to trigger subflow
var reqType = details[i].request_type_mv;
if(reqType == "Add Access"){
reqType = "Add";
}else{
reqType = "Remove";
}
var typeOfAcces = details[i].type_of_access;
var typeOfEnv = details[i].type_of_env;
var gr = new GlideRecord('u_user_access_provision_mapping');//Gliding data table to check which workflow to run based on the selected input combination on my MRVS
gr.addQuery('u_active',true);
gr.addQuery('u_item_name',current.cat_item);
gr.addQuery('u_type_of_access',typeOfAcces);
gr.addQuery('u_type_of_environment',typeOfEnv);
gr.query();
if(gr.next()){
if(gr.u_access_provisioned_by.toString() == "AD Group"){
coordinator.add({u_group:gr.u_ad_group.u_name,u_action:reqType,u_tkid:workflow.scratchpad.TKID });//passing the inputs to my coordintor object using add method of workflowCoordinator object
}
else{
coordinator.add({u_action:reqType,u_userid:workflow.scratchpad.TKID,u_role:gr.u_sailpoint_role},'Subflow - Sailpoint');//if the workflow needs to be called is different than what is used at the point of initialization (***) i need to pass the new workflow name as the second parameter here..
}
coordinator;//Must specify the variable holding the workflow coordinator object to return from the parallel workflow launcher activity .
}
}
This helped me to dynamically call different workflow based on what user filled in each row in MRVS in a single request.
Example Use Case: If we need to trigger multiple subflows based on each row in MRVS with different inputs to the subflow in a single request, I think this approach would be really helpful.
Let me know your comments , improvements and suggestions if any.
Thanks, for your time.
Mark this content as helpful if it really helps and been informative....
https://www.servicenow.com/community/now-platform-articles/workflow-coordinator-object-what-it-is-and-how-to-use-it-in/ta-p/2327604