docs: document using conditional operators in workflows (#9464)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user