docs: document using conditional operators in workflows (#9464)

This commit is contained in:
Shahed Nasser
2024-10-07 17:52:30 +00:00
committed by GitHub
parent 6e5d9acc4a
commit f3c8f5efef
2 changed files with 39 additions and 1 deletions
@@ -114,6 +114,44 @@ const myWorkflow = createWorkflow(
})
```
### No Conditional Operators
You can't use conditional operators in a workflow, such as `??` or `||`.
<Note>
Learn more about why you can't use if-conditions [in this chapter](../conditions/page.mdx#why-if-conditions-arent-allowed-in-workflows)
</Note>
Instead, use `transform` to store the desired value in a variable.
For example:
```ts
// Don't
const myWorkflow = createWorkflow(
"hello-world",
function (input: WorkflowInput) {
const message = input.message || "Hello"
})
// Do
// other imports...
import { transform } from "@medusajs/framework/workflows-sdk"
const myWorkflow = createWorkflow(
"hello-world",
function (input: WorkflowInput) {
const message = transform(
{
input
},
(data) => data.input.message || "hello"
)
})
```
---
## Step Constraints