# Configuring flow controls

Configure [Flow controls](https://docs.nexthink.com/platform/user-guide/workflows/creating-workflows/configuring-flow-controls) to drive workflow progression and decision logic based on values collected by the workflow or Nexthink data. These are the available Flow controls:

* **Condition**
* **Repeat**
* **Wait**
* **End block**

<figure><img src="https://268444917-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxJSUDk9NTtCHYPG5EWs3%2Fuploads%2Fgit-blob-3c2b84c77eed9f67d5adf121f560cb92c92cbeb0%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

## Condition flow control

The **Condition** block enables the branching of workflows based on values collected by the workflow or Nexthink data. The system evaluates a condition only once, at the point the workflow execution reaches it.

* **Conditions** accept only one exit point; parallel processing is not supported by Workflows.
* The **Else** branch, added by default when creating new conditions, is optional. The **Else** path runs whenever none of the defined conditions are met, ensuring the workflow continues without error.
* If a condition has no **Else** branch and none of the defined conditions are met, the condition will end with a “Default condition” error, and the workflow will stop running.
* The values that the conditions evaluate:
  * Thinklet outputs
    * Remote action outputs
    * Campaign responses
    * Service/API outputs
    * Workflow parameters
  * Database objects properties and their manual custom values: `device`, `user`
  * Conditions compare values using the following operators: Is, Is not, Greater than, Less than, Greater than or equal to, Less than or equal to, Contains, Does not contain, Is empty, Is not empty.

{% hint style="warning" %}
The system does not filter the list of available operators based on the allowed options for a given data type.
{% endhint %}

<div align="left"><figure><img src="https://268444917-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxJSUDk9NTtCHYPG5EWs3%2Fuploads%2Fgit-blob-1174d8763b176de020240a15e23e58d8a391e9e4%2Fimage.png?alt=media" alt="" width="489"><figcaption></figcaption></figure></div>

* **Name**: Enter a unique name for the condition flow control.
* **ID**: The system generates the ID automatically based on the name.
* **Description (optional)**: Describe the purpose of the condition and what it does. This information is useful for other users of the workflow who may not be familiar with it.
* **Add condition**: Add a condition to the condition flow control. You can use [manual custom fields](https://docs.nexthink.com/platform/administration/content-management/custom-fields-management#customfieldsmanagement-choosingmanualcustomfieldtypemanual) for condition values to drive workflow decision logic based on `user` or `device`-specific attributes.
  * Select the source and value of the dynamic data you want to evaluate.
  * Select the operator.
  * Select the value to compare against. Choose Custom value to enter a fixed reference value.
  * Add as many conditions as you need.
* **Else:** By default, the Else branch will be added to your conditions. Unselect it if you prefer the workflow to end with an error when none of the defined conditions are met.
* Click **Done** to commit the changes.

Once branches appear on the canvas, thinklets and other flow control blocks can now be added underneath them.

## Repeat flow control <a href="#designer-delay" id="designer-delay"></a>

The **Repeat** flow control lets you loop a group of actions, enabling retries, delays, and conditional exits. It's useful for:

* Retrying steps that might fail due to network issues or temporary errors.
* Waiting for asynchronous events, such as user confirmation or system updates.
* Repeating user interactions or actions with controlled timing.

When you use a Repeat block, it executes all actions inside the block multiple times until one of the defined exit conditions is met.

{% hint style="info" %}
Only one **Repeat** control is allowed per workflow.
{% endhint %}

### Configuring exit conditions

The Repeat block supports several types of exits. Each exit must be correctly connected in the workflow to function as intended:

* **Default exit**: Indicates a successful or completed state. This must be connected to a condition inside the Repeat block and followed by an exit branch with subsequent actions after the loop.
* **Exit after X times**: Automatically triggers when the loop reaches the defined maximum number of repetitions. This exit only requires a branch after the Repeat block and doesn’t depend on any conditions inside the loop.
* **Repeat after X minutes/hours**: Sets the delay between loop iterations. This condition must be linked to a branch inside the Repeat block and causes the loop to pause and repeat after the specified time.
* **Custom exits**: One or two optional exit conditions that end the loop early based on specific criteria. These should be connected to a branch inside the Repeat block.

See the example below to learn how to correctly link all exit branches

<figure><img src="https://268444917-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxJSUDk9NTtCHYPG5EWs3%2Fuploads%2Fgit-blob-bc97ae4730adaacfd0c83410f8cba33b15a409e8%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

* **Name**: Enter a unique name for the Repeat flow control.
* **ID:** The system generates the ID automatically based on the name.
* **Description (optional)**: Describe the purpose of the Repeat loop and what it does. This information is useful for other users of the workflow who may not be familiar with it.
* **Exit after**: Set the maximum number of repetitions. The loop stops when this number is reached. The maximum is 10.
* **Repeat after**: Set the delay between loop iterations. The workflow pauses for this amount of time before retrying the block. You can enter the value in minutes or hours.
* **Add custom exit**: Define one or two custom exits. These are triggered when a condition inside the loop is met.

## Wait flow control <a href="#designer-delay" id="designer-delay"></a>

The **Wait** flow control lets you pause a workflow before continuing to the next step. Use it to:

* Delay actions for a defined period.
* Wait based on user input or conditions.
* Spread workload to avoid API throttling.
* Coordinate with external systems via API.

<div align="left"><figure><img src="https://268444917-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxJSUDk9NTtCHYPG5EWs3%2Fuploads%2Fgit-blob-168c4d9c695c876690aecb55cfca93a20f5de4b6%2Fimage.png?alt=media" alt="" width="489"><figcaption></figcaption></figure></div>

* **Name**: Enter a unique name for the Wait flow control.
* **ID:** The system generates the ID automatically based on the name.
* **Description (optional)**: Describe the purpose of the Wait and what it does. This information is useful for other users of the workflow who may not be familiar with it.
* **Type:** The Wait thinklet supports two kinds:

<details>

<summary>Time delay</summary>

When selecting **Time delay**, the workflow pauses for a specified period, then automatically resumes. You can choose from three time options:

* **Fixed**: Set a constant wait defining a static duration. The maximum supported delay is **14 days**.
* **Dynamic**: Use the output of a previous thinklet or workflow parameter to dynamically define the wait time. When configuring:
  * Select the **Thinklet** or workflow parameter that provides the delay value.
  * Depending on the case, choose:
    * **Status** for remote actions thinklets.
    * **Selected action ID** for user input, for example, responses from campaigns or message thinklets.
    * Select a specific workflow parameter value.
  * Define the time unit coherent with the expected output of the previous thinklet or workflow parameter.
* **Random**: Set a random delay range.

{% hint style="info" %}
**Random** time delays help avoid overloading external systems—such as APIs—by preventing all workflow instances from executing simultaneously.

**Dynamic** time delays to adapt workflow pause behaviors based on dynamic inputs. Refer to [Creating workflows](https://docs.nexthink.com/platform/user-guide/workflows/creating-workflows/..#building-adaptive-wait-behavior-in-workflows) documentation for a use case of dynamic time delays in a Wait thinklet.
{% endhint %}

<div align="left"><figure><img src="https://268444917-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxJSUDk9NTtCHYPG5EWs3%2Fuploads%2Fgit-blob-9f8b3c659529119468b47353b290215304b6c0eb%2Fimage.png?alt=media" alt="" width="491"><figcaption></figcaption></figure></div>

</details>

<details>

<summary>API listener</summary>

When you select API listener, the workflow pauses and listens for an API call being made to the Trigger WaitFor Event workflow endpoint. Refer to the [Workflow API](https://nexthink.stoplight.io/docs/api/workflows-api) documentation for more information.

Configure up to five outputs to capture data from the external system making the call to Nexthink. Use these outputs to either make a branching decision with a condition in the workflow or to provide input information into subsequent thinklets.

<div align="left"><figure><img src="https://268444917-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxJSUDk9NTtCHYPG5EWs3%2Fuploads%2Fgit-blob-77400caa349ef39db03ef73e89d0af2777d1bf1c%2Fimage.png?alt=media" alt="" width="476"><figcaption></figcaption></figure></div>

* **Name**: Enter a unique name for the Wait flow control.
* **ID:** The system generates the ID automatically based on the name.
* **Description (optional)**: Describe the purpose of the Wait and what it does. This information is useful for other users of the workflow who may not be familiar with it.
* **Type**: Select the type of Wait required.
* **Timeout**: Set the timeout in minutes or hours. This dictates how long the workflow waits for the desired API call. When the timeout limit is reached, the workflow enters a failed state and stops processing.
* **Outputs**: Configure up to 5 outputs, which are collected from the API call being listened for. The ID of the output will be used for the parameters in the body of the call made to the Trigger WaitFor Event workflow endpoint.

{% hint style="info" %}
To use the Wait - API listener, ensure the external system knows about the execution and workflow it will interact with.

Send this information using the `{{sys.workflow.executionId}}` and `{{sys.workflow.workflowId}}` variables through a Service/API thinklet. The 3rd party system will then record this information to interact with the workflow. See the [format system value](#format-system-values) example of how to use these values [here](#format-system-values).
{% endhint %}

</details>

## End block <a href="#designer-endblock" id="designer-endblock"></a>

The **End** block enables you to define and report the final workflow outcomes.

When the workflow reaches an **End** block, the system logs the chosen **Outcome** and **Outcome details**. These execution results become available in:

* NQL data for queries.
* Corresponding **Workflow overview** dashboard, including KPIs.&#x20;

{% hint style="info" %}
Converge several branches into the same **End** block when they should report the same final outcome.
{% endhint %}

<figure><img src="https://268444917-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxJSUDk9NTtCHYPG5EWs3%2Fuploads%2FOZl99HWswjWorXxStGoB%2Fimage.png?alt=media&#x26;token=e113d8fb-1853-4d66-9eb7-1bece651d183" alt="" width="364"><figcaption></figcaption></figure>

* **Name**: Enter a unique name for the End block.
* **ID**: The system generates the ID automatically based on the name.
* **Description (optional)**: Describe the expected outcome of the workflow at this point in the logic tree. This information is useful for other users of the workflow who may not be familiar with it.
* **Outcome**: Select from a fixed list of outcomes the one that best describes what happens at this point:
  * Action taken
  * No action taken
  * Failure
  * Other
* **Outcome details (optional)**: Description of what happened during workflow execution, combining free text with `{dynamic values}` collected during the run. Keep it concise, especially if used in dashboards. Available in NQL and in the [Workflow overview dashboard](https://docs.nexthink.com/platform/user-guide/workflows/monitoring-workflows-dashboard).
