Make flow wait for tasks (created in another flow) to complete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2023 11:09 AM
Hi Team,
Requirement is to create tasks when change is created. (Able to achieve this via flow)
Change after going to implement state, tasks should be closed or else change cannot be moved to review state.
I am not sure on how to modify flow (to wait for tasks created in new state to get closed) which start when state changes to implement.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2023 11:37 AM
Hi,
You can use the script in a "Script" activity in your flow.
Here are the steps to do that:
Open the flow designer for the flow you want to modify.
Drag and drop a "Script" activity from the palette on the left onto the canvas.
Double-click on the "Script" activity to open its configuration panel.
In the "Script" section, paste the script code.
In the "Input" section, add the inputs required by the script. In this case, you need to add an input for the change request's sys_id.
In the "Output" section, add the outputs required by the next activity in the flow, if any.
Click "Save" to save the configuration.
Connect the "Script" activity to the previous and next activities in the flow as needed.
Save and publish the flow.
Once you run the flow, the script will run as part of the flow and check if the tasks created in the "New" state are closed or not before allowing the change request to move to the "Review" state.
Thanks,
Rahul Kumar
Thanks,
Rahul Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2023 12:09 PM
HI @rambo1 ,
To achieve your requirement, you can use a combination of ServiceNow Flow Designer and Business Rules. Here are the steps you can follow:
Create a new flow in Flow Designer. The trigger for this flow should be "When a record is updated" and the table should be "Change Request".
Add a condition in your flow to check if the state of the Change Request is changed to "Implement". You can use a "Condition" action for this purpose.
After the condition, add an "Action" action to create a new task for the Change Request. You can use the "Create Task" action for this.
Next, add another "Condition" action to check if the state of the Change Request is changed to "Review".
If the state is "Review", add a "Wait" action to wait for the tasks created in the "Implement" state to be closed. You can use the "Wait for Condition" action for this purpose.
In the "Wait for Condition" action, set the condition to check if all the tasks created in the "Implement" state are closed. You can use the "Task" table and the "state" field for this.
Here's an example code snippet for the Business Rule to trigger the flow when a record is updated:
var gr = new GlideRecord('change_request');
gr.addActiveQuery();
gr.addQuery('sys_id', current.sys_id);
gr.addQuery('state', 'IN', '3,4,5'); // Implement, Review, Closed states
gr.query();
if (gr.next()) {
gs.eventQueue('change_request.update', gr, gr.operation());
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi