Make flow wait for tasks (created in another flow) to complete

rambo1
Tera Guru

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.

6 REPLIES 6

Rahul Kumar17
Tera Guru

Hi,

 

To modify the flow to wait for tasks to be closed before moving a change request to the review state, you can add a Wait activity that waits for all the tasks to be closed before continuing the flow.

Here are the steps to modify the flow:

  1. Open the flow that is triggered when the change request state is changed to implement.
  2. Add a Wait activity after the task creation activity.
  3. In the Wait activity, configure the conditions for waiting. Specifically, you'll want to wait until all tasks associated with the change request are closed. You can achieve this by configuring the Wait activity to wait for a condition such as "Count of open tasks for the current change request is 0".
  4. Once the Wait activity is configured, add a Decision activity to check whether all the tasks are closed.
  5. If all tasks are closed, the flow can continue and the change request can be moved to the review state.
  6. If not all tasks are closed, the flow can send a notification or take some other action to alert users that the change request cannot be moved to the review state until all tasks are closed.

By adding a Wait activity and a Decision activity, you can modify the flow to wait for all tasks to be closed before continuing, ensuring that the change request can only be moved to the review state when all tasks are complete.

 

Thanks,

Rahul Kumar

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar

rambo1
Tera Guru

Hi Rahul,

Tasks are created in another flow which triggers when state is new.

I have check if those tasks are closed or not in flow which triggers when state is implement.

Could you please help me with this.

Hi,

To check if the tasks created in the "new" state are closed or not in the flow that triggers when the state is "implement", you can use a script step in the flow.

Assuming that the tasks are related to the change record, you can use GlideAggregate to query the Task table for tasks related to the change record and check their state. Here's an example script:

// Get the change request record
var change = new GlideRecord('change_request');
if (change.get(current.sys_id)) {

  // Query for tasks related to the change request
  var taskGr = new GlideAggregate('task');
  taskGr.addQuery('parent', change.sys_id);
  taskGr.addQuery('active', true);
  taskGr.addQuery('state', '!=', 'closed');
  taskGr.query();
  
  // If any tasks are not closed, set the change state to "implement" and exit the flow
  if (taskGr.next()) {
    change.state = 3; // 3 = "implement"
    change.update();
    gs.addInfoMessage('Cannot move to "Review" state as there are open tasks.');
    return;
  }
}

 

Thanks,

Rahul Kumar

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar

HI Rahul,

 

Your script will work for sure, but how do I use it in flow ?