> For the complete documentation index, see [llms.txt](https://developer.emporix.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.emporix.io/value-stream-modeller/learning-trails/trail/adding-conditional-step-in-value-stream.md).

# Adding a Conditional Step in a Value Stream

With the **Hello World** value stream from the first trail in place, you can add conditional logic to control when a process step runs. In this trail, you send an additional email notification only when the sender provides a specific form response.

You first create a new Make scenario, then apply a condition to the process step in the Hello World value stream.

## Creating a new scenario to respond to senders needing outreach

Similar to [Setting up a First Value Stream](/value-stream-modeller/learning-trails/trail/setting-up-a-first-value-stream.md), create a scenario named **Send a Survey Feedback** that sends another email to form recipients.

{% stepper %}
{% step %}

#### Create the Hello World Outreach Sent event

In **VSM**, go to **Events** -> **Event Registry** and create a new `hello_outreach_sent` event named **Hello World Outreach Sent**.

<figure><img src="/files/bgS6HMLEl1uTKCrZKndJ" alt="Hello World Outreach Sent event in Event Registry"><figcaption><p>Hello World Outreach Sent event in Event Registry</p></figcaption></figure>
{% endstep %}

{% step %}

#### Open the Hello World value stream

Go to **Value Streams** and open the **Hello World** process you created in the first trail.
{% endstep %}

{% step %}

#### Create a new scenario process step

Add a new process step and select **Create New Scenario**. Make opens a scenario template.

<figure><img src="/files/IKsNeyN5c2N52n8qXROU" alt="Create New Scenario option in the process step"><figcaption><p>Create New Scenario option in the process step</p></figcaption></figure>
{% endstep %}

{% step %}

#### Configure the Trigger Event connection

In the Make scenario, establish the connection in the **Trigger Event** module.

<figure><img src="/files/OZjbMZi2SC7iYoPp0jca" alt="Trigger Event webhook connection in Make" width="485"><figcaption><p>Trigger Event webhook connection in Make</p></figcaption></figure>
{% endstep %}

{% step %}

#### Add the first Set Variable from Process Context module

Add the **Set Variable from Process Context** module and configure it:

* Assign the data from the **Trigger Event**
* Select the **Hello World** value stream
* Use the latest Instance ID as the **Example Instance** – select the ID from the drop-down list. The ID at the top is from the latest instance
* Select **Hello World Feedback Sent** as the **Event Type**
* Select `email` from the **Field** drop-down list
* Enter `email` in the **Variable Name** field

<figure><img src="/files/h329zoHRarv2fhaf1TQZ" alt="First Set Variable from Process Context module configuration"><figcaption><p>First Set Variable from Process Context module configuration</p></figcaption></figure>
{% endstep %}

{% step %}

#### Add the second Set Variable from Process Context module

Add a second **Set Variable from Process Context** module and configure it:

* Assign the data from the **Trigger Event**
* Select the **Hello World** value stream
* Use the latest Instance ID as the **Example Instance** – select the ID from the drop-down list. The ID at the top is from the latest instance
* Select **Hello World Feedback Provided** as the **Event Type**
* Select `forms.0.payload.firstName` from the **Field** drop-down list
* Enter `firstName` in the **Variable Name** field
* Set **Raise Error when Null** to **Yes**

<figure><img src="/files/L2Moz2nKPl4YbzuJfjDe" alt="Second Set Variable from Process Context module configuration"><figcaption><p>Second Set Variable from Process Context module configuration</p></figcaption></figure>
{% endstep %}

{% step %}

#### Add the Gmail module

Add the **Gmail** (Send an Email) module. This trail uses Gmail as the example mail provider, as in [Setting up a First Value Stream](/value-stream-modeller/learning-trails/trail/setting-up-a-first-value-stream.md). You can use any supported provider.

<figure><img src="/files/FFqsB36LT8JgxYyb4rwR" alt="Gmail module in the Make scenario"><figcaption><p>Gmail module in the Make scenario</p></figcaption></figure>
{% endstep %}

{% step %}

#### Configure the Completion Event

In the **Completion Event** module, select **Hello World Outreach Sent** as the **Event Type**.
{% endstep %}

{% step %}

#### Save and run the scenario once

Save the scenario and select **Run once**. The scenario should look like this:

<figure><img src="/files/yLFA83m2sxdvTw4alPxp" alt="Complete Send a Survey Feedback scenario in Make"><figcaption><p>Complete Send a Survey Feedback scenario in Make</p></figcaption></figure>
{% endstep %}

{% step %}

#### Add the scenario to the value stream

In **VSM**, open the **Hello World** value stream. Add a new process step with the new scenario. **Send a Survey Feedback** is visible in the available scenarios list. Select it as the process step.

<figure><img src="/files/RyMmfpwgzjNkt7n6cxY2" alt="Send a Survey Feedback scenario added as a process step"><figcaption><p>Send a Survey Feedback scenario added as a process step</p></figcaption></figure>
{% endstep %}

{% step %}

#### Publish and activate the value stream

Select **Publish**, then confirm the value stream is active.
{% endstep %}

{% step %}

#### Activate the Make scenarios

Ensure the **Send a Survey on Hello World** and **Send a Survey Feedback** scenarios in Make are active.
{% endstep %}

{% step %}

#### Test the value stream

Re-run the value stream by sending a new trigger event. Use the same Postman request or Celonis Action Flow you used in [Setting up a First Value Stream](/value-stream-modeller/learning-trails/trail/setting-up-a-first-value-stream.md).

After you send the event, you receive an email requesting a form response. After you submit the response, you receive a second email with a thank-you message.

<figure><img src="/files/dkRwANfmItg5OC8lRc33" alt="Thank-you email after form submission"><figcaption><p>Thank-you email after form submission</p></figcaption></figure>
{% endstep %}
{% endstepper %}

## Applying conditional logic with JSON

Up to this point, the **Send a Survey Feedback** scenario runs for any form response. Limit the step so it runs only when the response is `indifferent` or `sad`. Apply a condition on the **Send a Survey Feedback** process step in the **Hello World** value stream.

{% stepper %}
{% step %}

#### Open the step filter configuration

Go to the **Hello World** value stream. On the **Send a Survey Feedback** process step, select **Add step filter**.
{% endstep %}

{% step %}

#### Enter the JSON Logic expression

Open the **Condition** tab. In the **JSON Logic Expression** field, enter the following expression:

```json
{
    "in": [
        {
            "context": "hello_feedback_provided.forms.0.payload.sentiment"
        },
        [
            "indifferent",
            "sad"
        ]
    ]
}
```

<figure><img src="/files/jZZqEgl0eebefHZqMOVt" alt="JSON Logic Expression in the Condition tab"><figcaption><p>JSON Logic Expression in the Condition tab</p></figcaption></figure>

The condition maps variables to the relevant fields in your process context.
{% endstep %}

{% step %}

#### Save the condition

Save the expression as the process step condition and then save the value stream.
{% endstep %}

{% step %}

#### Publish and activate the value stream

Publish the new version of the value stream and ensure it is active. Only responses with **indifferent** or **sad** values run the **Send a Survey Feedback** step.

The value stream completes regardless of the form response.
{% endstep %}

{% step %}

#### Test with different form responses

Send the event request again using Postman or Celonis Action Flow. You receive a form submission request again.

* Submit **happy** as the response – the **Send a Survey Feedback** process step does not run.
* Submit **indifferent** or **sad** – the **Send a Survey Feedback** step runs and you receive another email with the thank-you message and next-step information.
  {% endstep %}

{% step %}

#### Verify the results in the debugger

Open debug mode to verify the value stream behavior. Go to the **Hello World** value stream and choose the debugger action.

<figure><img src="/files/Q18heUcMRoxoe2xHFM4P" alt="Hello World value stream in debug mode"><figcaption><p>Hello World value stream in debug mode</p></figcaption></figure>

* **Happy** response – the step was filtered

<figure><img src="/files/aVPmBrdUwVPGYaJLCWFp" alt="Filtered step for a happy response"><figcaption><p>Filtered step for a happy response</p></figcaption></figure>

* **Indifferent** or **sad** response – the step was invoked

<figure><img src="/files/8gHpYp4Kx41ETtfWnoP4" alt="Invoked step for an indifferent or sad response"><figcaption><p>Invoked step for an indifferent or sad response</p></figcaption></figure>
{% endstep %}
{% endstepper %}

You can also use events as conditions on process steps. Multiple events can be assigned to a step or group of steps, and both `IN (OR)` and `AND` operators are supported. This is the preferred option when you only need to test for the presence of an event.

<figure><img src="/files/AzG1FZITH63Ee3GNCXnw" alt="Event-based step filter configuration" width="552"><figcaption><p>Event-based step filter configuration</p></figcaption></figure>

{% hint style="info" %}

* To learn more about conditional logic in VSM, see [Conditions](/value-stream-modeller/value-stream-designer/process-components/conditions.md).
* To learn more about JsonLogic, see [Supported Operations](https://jsonlogic.com/operations.html) and [Play with JsonLogic](https://jsonlogic.com/play.html).
  {% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developer.emporix.io/value-stream-modeller/learning-trails/trail/adding-conditional-step-in-value-stream.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
