> 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/vsm-guides/learning-trails/trail/adding-conditional-step-in-value-stream.md).

# Adding a Conditional Step in a Value Stream

Add conditional logic to the Hello World value stream so outreach runs only for specific form responses.

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](/vsm-guides/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**.
{% 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.
{% endstep %}

{% step %}

#### Configure the Trigger Event connection

In the Make scenario, establish the connection in the **Trigger Event** module.
{% 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
  {% 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**
  {% 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](/vsm-guides/learning-trails/trail/setting-up-a-first-value-stream.md). You can use any supported provider.
{% 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:
{% 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.
{% 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](/vsm-guides/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.
{% 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"
        ]
    ]
}
```

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.

* **Happy** response – the step was filtered
* **Indifferent** or **sad** response – the step was invoked
  {% 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.

{% hint style="info" %}

* To learn more about conditional logic in VSM, see [Conditions](/vsm-guides/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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
