- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2015 08:02 AM
I would like to call a workflow from a workflow, but I need to set a different current record in the sub flow. I want the parent workflow to call the sub flow and wait for the return. I have been using the methodology from this: https://wiki.servicenow.com/index.php?title=Using_Subflows
This calls the sub flow and waits for completion, but does not set the current record in the sub flow, so I pass the record needed as input and use this code in the sub flow:
// Setup current record from input
current = new GlideRecord('u_job_set');
current.get(workflow.scratchpad.u_current_record);
current.state = 1;
// Setup context
context.table = 'u_job_set';
context.id = current.sys_id;
context.state = 'executing';
This works, but there are some timing issues, and I suspect there is more that needs to be done. I found this in the AWS workflows.
My other option is to have a run script that launches the workflow. This seems to work better in the sub flow, but does not wait for subflow completion:
var jobSet = new GlideRecord('u_job_set');
jobSet.get(workflow.scratchpad.cRecord);
var wf = new Workflow();
var vars = {};
var workflowId = wf.getWorkflowFromName('Sub Flow 1');
wf.startFlow(workflowId, jobSet, "", vars);
So, Is there a way to pause after the workflow launch here? I know I can do it with some business rules and database variables, but looking form something cleaner.
Or, is there a better way to set the current record in the first case? I am also using the parallel flow launcher and the WorkflowCoordinator object to launch subflows. These behave just like the first example.
J.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2015 10:05 AM
James,
What you can do is in your Parent Workflow after the Runscript which invokes the Workflow on Job table, have a Wait For Condition to wait for some flag like a custom field 'u_job_wait'.
Now, in the Workflow which is running on the Job at the end of the Workflow, update the record of the parent with u_job_wait to true which then will have the Workflow move forward.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2015 10:02 AM
I have a manager workflow that launches a Job Set subflow. The Job Set flow launches Job subflow.
The manager workflow inserts the job sets into the u_job_set table, and the jobs into the u_job table.
Each workflow uses its respective table. I want the flows to execute asynchronously (run and wait for completion).
The second example I have is from a runscript invoking a workflow. I am not sure what you mean by having them dependent on each other.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2015 10:05 AM
James,
What you can do is in your Parent Workflow after the Runscript which invokes the Workflow on Job table, have a Wait For Condition to wait for some flag like a custom field 'u_job_wait'.
Now, in the Workflow which is running on the Job at the end of the Workflow, update the record of the parent with u_job_wait to true which then will have the Workflow move forward.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2015 12:19 PM
I think this is going to work for me. It seems to solve my problems. Thanks!
James.