# Creating a Value Stream

## Introduction

Creating a value stream happens in the edit mode.\
When working in edit mode, you have a possibility to work on one draft version of the value stream, it's not possible to save multiple draft versions.

Whenever you work on the draft and do some changes, they are autosaved overwriting the previous draft.

The draft of each value stream is visible together with the active value stream in the dashboard. Whenever you click on a value stream that was not published yet, it opens in the edit mode for the process. In this case, when a process was not published yet, the **Last Published** date refers to the time when it was created and autosaved for the first time.

<figure><img src="https://2734760799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8dAaH7DfB59pzZwLxmur%2Fuploads%2Fgit-blob-9ce59960bae59c996cb516c8567845a75c59fdb3%2Foe_draft_view_vs.png?alt=media" alt=""><figcaption></figcaption></figure>

## Creating a value stream

To start with a value stream:

1. In the **Management Dashboard**, go to **OE** -> **Value Streams** and choose **Create Value Stream**.
2. Enter a **name** for the new value stream and choose **Create**. Without entering the name, you cannot move to the next steps.\
   There are no restrictions on using special characters in names, and you can create separate value streams with the same name.

<figure><img src="https://2734760799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8dAaH7DfB59pzZwLxmur%2Fuploads%2Fgit-blob-1fd3136b7d7bbf6cb34921e18c0562e61468e8ae%2Fstep0_vs.png?alt=media" alt=""><figcaption></figcaption></figure>

## Triggers

Select the trigger that you want to use in the process. You can choose between an event and a Make scenario:

### Events

Choose an [event](https://developer.emporix.io/oe/management-dashboard/events) from the list of events that are created in your tenant. If you have a large number of events, you can narrow the list down by the event’s name using the search field.

### Scenario

To set up a Make scenario as a trigger, you can use the following options:

* Choose an existing scenario directly from the list of available scenarios. To edit the scenario, you can use the **Edit Scenario** action and move directly to the edit mode of the specific scenario in Make.
* Choose **Go to Scenarios** to create a new triggering scenario in Make.

  To learn about Make's scenarios, check out the [Make Scenarios](https://www.make.com/en/help/scenarios) documentation.
* Choose **Go to Templates** to use a Make template that is already available publicly or for the team.

  To learn about Make's scenarios templates, check out the [Make Scenarios Templates](https://www.make.com/en/help/scenarios/scenario-templates) documentation.

The scenario / process must have at least one occurrence of the **Start New Orchestration** module, otherwise it is filtered out from a list of available scenarios / processes, or disabled if it’s not configured properly. The module is required because every trigger starts a new OE instance. If the module has not been added, OE doesn’t receive any notifications about the new triggers.

### Timer Event

You can use a timer event for setting up a trigger that starts a value stream on a specified schedule, and for setting up how long the process should be paused before it wakes up again.

You can set up the timer trigger in three ways, as a context variable, single event, or a repeating event.

* **Use Context Variable**: you can use it for the mid triggers, the timer uses a variable that is stored in a process context of a value stream, the trigger works when a Make scenario, or a Cloud Function, provide a point in time when a value stream should wake up.

The variable should be configured in a `.<event_name>.<content_variable_name>` format, for example: `.sleeping_until.until`, where the wake up trigger is the `until` property in the `sleeping_until` event. It has to be a cron expression or an ISO 8601 compliant date.

{% hint style="warning" %}
When writing the expression pay special attention to the format - remember to include the dot (.) before the event name and the content variable name.
{% endhint %}

The context variable can reference to a time during which a process context should be paused, this can be configured together with a Make scenario. For example:

<figure><img src="https://2734760799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8dAaH7DfB59pzZwLxmur%2Fuploads%2Fgit-blob-0a567817993175ddba4f77876cbe3a15e6ddd7bf%2Fuse_context_variable.png?alt=media" alt=""><figcaption></figcaption></figure>

The context variable is referenced as `.sleeping_until.sleep_until` using the `<event_name>.<content_variable_name>` expression format, where:

* `sleeping_until` is the event name, selected as **Event Type** in the **Completion Event** Make module

<figure><img src="https://2734760799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8dAaH7DfB59pzZwLxmur%2Fuploads%2Fgit-blob-63f3beb9387be7ebdb98f050b51397a136fcac8c%2Ftimer_variable_vs.png?alt=media" alt="" width="553"><figcaption></figcaption></figure>

* and `sleep_until` is the content variable name, referenced to by a **JSON String** in the **Completion Event** Make module

<figure><img src="https://2734760799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8dAaH7DfB59pzZwLxmur%2Fuploads%2Fgit-blob-ca4a51481780387ec2e47e94a26574bfd7bb0f29%2Ftimer_variable2.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

To set the variable in Make, you can use the **Set Variable** module.

<figure><img src="https://2734760799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8dAaH7DfB59pzZwLxmur%2Fuploads%2Fgit-blob-e23f14c8bacab99939bdc570947e26b1b6a68751%2Ftimer_event_variable.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

* **Single Event**: choose a specific date and time when an event should trigger a value stream
* **Repeating Event**: define recurring schedules using precise timing rules, such as every Tuesday, every 30 minutes or every month at specified time.

<figure><img src="https://2734760799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8dAaH7DfB59pzZwLxmur%2Fuploads%2Fgit-blob-8b5c2bc1601e72b89930131d94065d92bd4f58e8%2Ftimer_event2.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

When you select a trigger, you can see that the user interface provides confirmation that the selection was saved. You can collapse the section using the **caret** icon in the step's heading line, or simply go to the next step by choosing the **plus** icon.

<figure><img src="https://2734760799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8dAaH7DfB59pzZwLxmur%2Fuploads%2Fgit-blob-016201b6e691d4fbb60d39b630dc8eedefe9a2f2%2Fstep1_vs.png?alt=media" alt="" width="553"><figcaption></figcaption></figure>

## Process steps

After choosing the trigger, select the process step that you want to perform. Each process step can use a single or multiple Make scenarios, call a child value stream, or call a Cloud Function.

* To add a process step with Make scenarios, go to the **Scenarios** tab.
* To add a process step with another value stream included, go to the **Subflows** tab.
* To add a Cloud Function as a process step go to the **Cloud Functions** tab.

### Scenario as a process step

You can choose a Make scenario that is already created in Make and visible in the list in the process step.\
If you don't want to select an existing scenario, choose **Create New Scenario** to create a new process step scenario, or **Go to Scenarios** to check for scenarios that are prepared to be used publicly or available for your team only. The **Create New Scenarios** and **Go to Value Streams** actions open a new tab with the Make application.

After going to Make, ensure you are working in the right organization. The name should reflect your tenant name in OE. To check if the organization is the correct one, it's enough to hover over the Make's sidebar, the name is visible at the top. Then, you can either click directly on the template to start working with it, or choose the **Start guided setup** option to continue.\
Every Make scenario used in a process step must start with a **Trigger Event** and have the **Completion Event** module.

{% hint style="danger" %}
If you click on any of the Make's sidebar nodes, it switches off the template and redirects you the selected section in Make. It's not possible to get back to the template.
{% endhint %}

Additionally, ensure that the scenario is active. The scenario toggle should be switched from OFF to ON.\
To learn about Make's scenarios, check out the [Make Scenarios](https://www.make.com/en/help/scenarios) documentation.

<figure><img src="https://2734760799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8dAaH7DfB59pzZwLxmur%2Fuploads%2Fgit-blob-c5a188dc5f951e5866812e3bbe602dcd39a96203%2Fstep2.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

Each process step can be made of multiple Make scenarios that can be rearranged at any time using the drag and drop functionality (**hamburger** icon).

<figure><img src="https://2734760799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8dAaH7DfB59pzZwLxmur%2Fuploads%2Fgit-blob-8c5a99ae631b75d0acc42c86e292a6a7ebd6b0da%2Fmultiple_scenarios.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### Value stream as a process step

In the **Subflows** tab, you can choose a value stream that you'd like to include in your parent value stream. By default, value streams are all separate processes, but they can also work together in a parent-child relationship. This is useful if you want to create a more complex process to address a larger business use case. In such a situation, you can embed processes within one another, without the need to run them separately.

{% hint style="warning" %}
Value streams that have an **invalid** or **pending** status are not visible in the subflows list.
{% endhint %}

<figure><img src="https://2734760799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8dAaH7DfB59pzZwLxmur%2Fuploads%2Fgit-blob-6561fddab4f80ce245dd2f1179a8c03916b625fd%2Fsubflows.png?alt=media" alt="" width="502"><figcaption></figcaption></figure>

### Cloud Function as a process step

In the **Cloud Functions** tab, you can choose one of the already enabled Cloud Functions or create a connection to a new one.

To start creating a connection to a Cloud Function choose **New Cloud Function**, this opens a window where you can create Cloud Functions groups and structure them in parent-child relationship. To create a single Cloud Function connection, first create a group. When you have the group created you can then move to the **Definition** tab, where you can specify the Cloud Function configuration.

You can create multiple Cloud Function connections within a group.\
Groups allow aggregation of multiple Cloud Function connections under a single set of authentication credentials.

<figure><img src="https://2734760799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8dAaH7DfB59pzZwLxmur%2Fuploads%2Fgit-blob-71e9fce553f85f25d984b6c40834b2beade3a144%2Fcloud_function1.png?alt=media" alt=""><figcaption></figcaption></figure>

In the **Definitions** tab, provide the following setup for a Cloud Function connection:

* Display Name - Cloud Function name
* HTTP Method - GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS
* Invocation URL - it's a URL that is used to call a Cloud Function which is created in Azure, AWS or GCP.
* Cloud Provider - choose between predefined providers - Azure, AWS or GCP. The providers offer the infrastructure and services that enable the function to execute in response to specific events or requests. It's necessary to select one of them, to have the relevant authentication options.
* Authentication mode - you can create Cloud Functions with or without authentication method. If you select Azure as the cloud provider, you can choose between the following authentications:

  * None
  * Basic - a username and password are used when making a request to a server, it's a part of the HTTP protocol.
  * Oauth2 - allows third-party applications to have a limited access to the data, through an authorization server.
  * Function Key - a specific authentication mode used only in Microsoft Azure Functions, access to an Azure Function is secured using a shared key, known as a function key. If you make a request to the function, you must include this key as part of the request to authenticate and gain access.\
    The Authentication Mode options in OE correspond to the Cloud Providers configurations.

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

Cloud Functions allow for dynamic, context-aware processing where the body of the function call is determined by applying a JQ filter to the context. The result of this filtering extracts the key body, which becomes the function's payload. Other keys in the result are mapped to replacement variables and can replace placeholders in the CF definition.

Replacement variables are defined in the CF's URL using the syntax `{{.varName}}`. When the JQ filter is applied, any value under the key `varName` is substituted into the corresponding placeholder in the URL. This system enables flexible customization of both the function payload and its endpoint through context-specific values.

After you create the connection to the Cloud Function and add it to the process step you can check the edit mode of the step with three input texts:

<figure><img src="https://2734760799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8dAaH7DfB59pzZwLxmur%2Fuploads%2Fgit-blob-b7ae1bfd9f366353c537d0dc87a66a80b17dd6da%2Fcf.png?alt=media" alt="" width="554"><figcaption></figcaption></figure>

* Run Context - loads the last run context
* JQ Expression

  ```json
  {"urlParam": "urlVal", "qParam": "qVal", "body": {"key":"value"}}
  ```
* Curl to the Cloud Function

  ```json
  curl --location '{{Cloud Function URL}}'\
     --header 'Content-Type: application/json' \
     --data '{}'
  ```

  <figure><img src="https://2734760799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8dAaH7DfB59pzZwLxmur%2Fuploads%2Fgit-blob-091d23a7755c950375ebcd8871b21e864e6f357b%2Fcf_edit.png?alt=media" alt="" width="552"><figcaption></figcaption></figure>

  For a value stream that had already run, you can see the context data included, for example:

  <figure><img src="https://2734760799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8dAaH7DfB59pzZwLxmur%2Fuploads%2Fgit-blob-1014e44412443f5612c43159f5f276ef800ab09f%2Fcf_edit2.png?alt=media" alt="" width="548"><figcaption></figcaption></figure>

The three text fields are visible only in the edit mode, when you check a value stream in view mode, you can see the Input field only.

<figure><img src="https://2734760799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8dAaH7DfB59pzZwLxmur%2Fuploads%2Fgit-blob-11b1723a0de34041c87cf757315c78f73c740d06%2Fcf_view.png?alt=media" alt="" width="554"><figcaption></figcaption></figure>

{% hint style="info" %}
For testing the JQ expressions, you can use [JQ Playground](https://www.devtoolsdaily.com/jq_playground/).
{% endhint %}

When you select a process step, the user interface confirms that your selection has been successfully saved, just as it does for triggers. You can then collapse the section, proceed to the next step, or complete the scenario creation using these two steps.

The value streams can be created using many combinations, for example:

* A trigger with one process step
* A trigger with many process steps
* A trigger followed by a process step, another trigger and more steps

{% hint style="warning" %}
If you use a Make scenario as a mid trigger, make sure it ends with a "notify event" module that is configured to send notifications about the completed scenario to OE. You need to use the OE Instance ID, `oe-instanceid`, to wake up a value stream. For details, see [Setting a Trigger to Wake Up a Paused Value Stream](https://developer.emporix.io/oe/value-streams/working-with-value-streams/trigger-to-wake-up-a-paused-process).
{% endhint %}

<figure><img src="https://2734760799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8dAaH7DfB59pzZwLxmur%2Fuploads%2Fgit-blob-ca631c0ba439c19759ed8596eb1c3250e1ffb6e5%2Fstep3.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

## Ending the value stream

1. When your value stream is ready, choose **Publish** to save your configuration.

{% hint style="warning" %}
Your value stream is created but is not active yet.
{% endhint %}

2. To activate the value stream, use the toggle that changes the inactive state to active. You can do that straight away in the edit mode, or from the processes list.

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

When your value stream is ready, it runs every time the specified trigger event is received. Each run of a value stream creates a new instance.

You can check your value stream instances in the [Value Stream Debugger](https://developer.emporix.io/oe/troubleshooting/value-streams-debugger). The debugger helps in troubleshooting and reviewing the whole process flow, as well as single process steps.
