call a subflow script not working

ElizaDC
Kilo Expert

Hi everyone,

We have a script which calls out a subflow to run within a parent workflow. Previously, we had these subflows integrated directly within the main workflow (see screenshot below), but this practice has caused some issues with Geneva version.

subflow.jpg

Now with the script, we have this set-up:

subflow2.jpg

This is the script currently:

var
gr = new GlideRecord('wf_workflow');

  1. gr.addQuery('name', 'SC Assign RITM to Appropriate SD');
  2. gr.query();

if
(gr.next()) {

var
wf = new Workflow();

var
workflowId = '' + gr.sys_id;

var
vars = {};

  1. wf.startFlow(workflowId,
    current, current.operation, vars);

}

However, we can't seem to make it work despite tweaking the script above. Appreciate any expertise you can extend on this one, thanks!

1 ACCEPTED SOLUTION

This worked for me:



var wf = new Workflow();


var workflowId= wf.getWorkflowFromName('SC Assign RITM to Appropriate SD');



if (workflowId) {


var vars = {};


var context = wf.startFlow(workflowId,current,"update",vars);


}


View solution in original post

9 REPLIES 9

staceyrocheleau
Kilo Guru

I've scripted workflows before.



This might be easier for getting your workflow but not sure if it really produces anything different. Have you tried passing in an operation value instead of current.operation() just to see if it behaves any differently?



var wf = new Workflow();


var workflowId= wf.getWorkflowFromName('SC Assign RITM to Appropriate SD');



if (workflowId) {


var vars = {};


  1. var context = wf.startFlow(workflowId,current,"update",vars);

gs.log("context of workflow: " + context);



}




One question: if the subflows aren't working (yikes), your script will return once it triggers the workflow and won't wait for the workflow to complete. Are you going to put in a wait condition in your workflow and have the subflow fire some kind of event so yours knows to continue? Because with the subflows, it would wait for the workflow to complete and you could get return values from it.


Another idea would be to auto trigger those 2 subflows on your record since they run every time anyway. Then have this workflow wait for them to broadcast an event. So your workflow would start with a wait for event or condition activity and those other 2 would run independently and broadcast the event at the end to let it know they're done so it can continue on.



I'm still concerned about the subflow issue with Geneva. I'm about to test because I use subflows.


I ran some tests with our workflows containing subflows and they all executed fine. I'm wondering what issue you had?


The issue we're having with Geneva is when we try publishing a workflow that has the same set of subflows being used in other workflows, it just hangs and stuck in a loop. The reason given by ServiceNow is that in case we have some update sets open and also use the same set of subflows in them, the wf is looking for the latest version of these subflows and wouldn't want to have these published until the latest one is published (problem is, this update set that has the latest version of subflows might be in a situation wherein we are still waiting for more information or are still in UAT phase). Subflow call-out is their proposed resolution.