How to Execute a Step Only If a Certain Value is Present in the Previous Step?

This topic was automatically generated from Slack. You can find the original thread here.

how can I execute a step only if a certain value is present in the previous step?

To execute a step only if a certain value is present in the previous step, you can use an if statement in your component’s run method. For example, let’s say the previous step is named previousStep and you want to check if it has a value called targetValue. You can do this: export default defineComponent({ async run({ steps, $ }) { if (steps.previousStep.targetValue) { // Your code to execute when the targetValue is present } }, }); This code will only execute the code within the if block if steps.previousStep.targetValue is present (i.e., not undefined, null, false, 0, NaN, or an empty string).

Step1: produces a result with a value True or False.
If True, I want Step3 executed
If False, I want to skip Step3 and execute Step4
How can I construct this and put it as Step2?

To achieve this, you can use an if statement in Step2 to conditionally execute Step3 or Step4 based on the result from Step1. Here’s an example of how you can construct Step2: export default defineComponent({ async run({ steps, $ }) { if (steps.Step1.result === true) { // Your code for Step3 } else if (steps.Step1.result === false) { // Your code for Step4 } }, }); In this example, replace // Your code for Step3 and // Your code for Step4 with the actual code you want to execute for Step3 and Step4, respectively.