Pass variables using Parallel Flow Launcher

gldecurtins
Mega Expert

Hi all

I do want to trigger a sub-workflow out of a workflow. The workflow shall pass two parameters to the sub-workflow. How can this be achieved?

Input 1: action, select box, choices('create','update','delete');

Input 2: CI, list collector pointing to cmdb_ci

The Parallel Flow Launcher should trigger one sub-workflow for every CI selected in the list collector.

I did check the "Scrpt Workflow" checkbox. Inputs seems to be quite static, isn't it?

javascript:

coordinator = new WorkflowCoordinator( {workflow:'Workflow - Sub'} );

for (var i = 0; i < current.variables.var_list.length; i++) {

      coordinator.add( {u_action: 'delete'} )

      coordinator.add( {u_cmdb_ci: current.variables.var_list[i]} )

      workflow.debug(current.variables.var_list[i]);

}

coordinator;

While testing the workflow the Parallel Flow Launcher fails: "Cannot start: no flows or already running? flows: 0, running: 0".

What is the proper way to trigger n sub-workflows passing multiple inputs?

Cheers

-Luca.

1 ACCEPTED SOLUTION

russ_sarbora
ServiceNow Employee
ServiceNow Employee

I'm not sure which field you have this script in, Inputs or Workflow script field that appears after checking the Advanced checkbox? Make sure its in that Workflow script field, and you'll need to take out the javascript: line



Also, your loop is adding 2 subflows to the coordinator every pass through. I think what you want to do is add 1 subflow with 2 inputs.


coordinator.add( {


  u_action : 'delete',


  u_cmdb_ci : current.variables.var_list[i]


});




It should look something like this:



Screen Shot 2015-02-12 at 11.48.30 AM.png


View solution in original post

5 REPLIES 5

russ_sarbora
ServiceNow Employee
ServiceNow Employee

I'm not sure which field you have this script in, Inputs or Workflow script field that appears after checking the Advanced checkbox? Make sure its in that Workflow script field, and you'll need to take out the javascript: line



Also, your loop is adding 2 subflows to the coordinator every pass through. I think what you want to do is add 1 subflow with 2 inputs.


coordinator.add( {


  u_action : 'delete',


  u_cmdb_ci : current.variables.var_list[i]


});




It should look something like this:



Screen Shot 2015-02-12 at 11.48.30 AM.png


Hi



I've got the Parallel Flow Launcher to trigger the correct amount of sub-flows. But the sub-flows do not create the tasks as expected.


I do trigger the sub-flows using the following script:



javascript:



    coordinator = new WorkflowCoordinator({


    workflow: 'Group decommissioning - Sub'
    });



var groups = current.variables.var_list_u_group.toString().split(',');


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


    coordinator.add({


    u_ref_u_group: groups[i]


  });


}



coordinator;



If my list has got about 3 groups in it, it does trigger 3 sub-flows. But only 1 task gets created. If I close that task, then all 3 tasks are closed.



The RITM workflow context does look like:


{


  "coordinator": {


    "d61f6f186fc37100cde14c992e3ee4f3": {


    "flows": [


  {


    "contextId": "7634b7586fc37100cde14c992e3ee428",


    "index": 0,


    "inputs": {"u_ref_u_group": "64464fd26f603d04e0204c992e3ee4ff"},


    "status": "running",


    "workflow": "Group decommissioning - Sub"
    },


  {


    "contextId": "b2347f586fc37100cde14c992e3ee434",


    "index": 1,


    "inputs": {"u_ref_u_group": "d61e286c212c7580aeb39a29585d61a2"},


    "status": "running",


    "workflow": "Group decommissioning - Sub"
    },


  {


    "contextId": "3a347f586fc37100cde14c992e3ee434",


    "index": 2,


    "inputs": {"u_ref_u_group": "70db582621e8f9c0aeb39a29585d6155"},


    "status": "running",


    "workflow": "Group decommissioning - Sub"
    }


  ],


    "settings": {


    "errormode": "stop",


    "max": 250,


    "next": 3,


    "originator": "3a34b7586fc37100cde14c992e3ee427",


    "parent": "2c243f582b0735002a8d544b94da1535",


    "poolsize": 50,


    "running": 3,


    "totalFlows": 3,


    "workflow": "Group decommissioning - Sub"
    }


  }


  }


}


Any idea why all the tasks relate to each other?



Regards


-Luca.


I did add a Timer (10 seconds) before I do run the "Create Task" activity. Now it's working. Can it be done without timer?


Gian,



Were you able to find out why the timer was required ? I have the same problem and the timer fixed it but not sure why.