Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated edge condition docs #511

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 40 additions & 16 deletions docs/build/paths.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,58 @@ and configuration tips.

## Path Conditions

There are 4 types of Path Conditions that define whether the Workflow will
There are four types of Path Conditions that define whether the Workflow will
proceed to the next Step when executed:

1. Always (the next Step will always run after the execution of the prior Step
is completed)
2. On Success (the next Step will run only if the execution of the prior Step
_succeeded_)
3. On Failure (the next Step will run only if the execution of the prior Step
_failed_)
4. Matches a JavaScript Expression (the next Step will only run if the condition
or custom expression evaluates to be true)
1. **Always**: the next Step will always run after the execution of the prior
Step is completed
2. **On Success**: the next Step will run only if the execution of the prior
Step _succeeded_
3. **On Failure**: the next Step will run only if the execution of the prior
Step _failed_
4. **Matches a JavaScript Expression**: the next Step will only run if an
expression evaluates to be true

![Path Conditions](/img/path_conditions.png)

## Writing JavaScript Expressions for Custom Path Conditions

Write your own JavaScript expression if you want to define a **custom
condition** that evaluates the initial state of the step.
Create a **custom condition** with a JavaScript expression. This evaluates
against the state produced by the previous Step.

The workflow will only continue to the next step if if the JavaScript expression
evaluates to be true.
```
state.data.form['@name'] === "Register New Patient"
```

This is a regular Javsacript expression with `state` in scope. If the expression
evaluates to true (or anything _truthy_), the Path will be followed and the next
Step will be executed.

![Custom Conditions](/img/path_js_expression.png)

## Disable Paths to deactivate
Examples of valid conditions include:

- Run if there are no errors: `!state.errors`
- Run if some value exists on state: `state.has_valid_email_address`
- Run if a data array contains any items: `state.data.length > 0`
- Run if data includes one item which matches criteria:
`state.data.includes(item => item.age > 18)`
- Run if the last Step received a HTTP error: `state.response.statusCode >= 400`

In a custom expression you **cannot** do any of the following:

- Use adaptor functions
- Use Lazy State references (`$`).
- Use control statements like `if`, `while`, `for`, etc

## Disabling Paths

Disabling a path will prevent any of the downstream Steps from running,
regardless of the condition or state.

This can be a useful way of temporarily deactivating part of your workflow.

To "deactivate" part of your Workflow and the Steps that follow a specific Path
sequence:
To disable a path:

1. Click on the `Path` you want to deactive
2. Select the `Disable this path` checkbox