How can I split paths in a workflow based on different conditions?

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

Krischan : Hi again, I have a workflow in mind where some steps (eg getting data from a google sheet) would only be executed, if a certain condition is fulfilled. Can I leave steps out in a workflow? And how would I split paths in a workflow based on certain conditions? Can I just start a different workflow from a workflow? Thanks in advance!

1 Like

Dylan Sather (Pipedream) : yes, there are a couple of options here:

You can kick off a new workflow from a workflow. Typically it’s easiest to make an HTTP request to trigger the new workflow. If you wanted to send data to one or another workflow conditionally, you could do:

if (myCondition) {
  $send.http({
    url: "[workflow1.m.pipedream.net](http://workflow1.m.pipedream.net)",
    method: "POST",
    data: {
      name: "Luke",
    }
  })
} else {
  $send.http({
    url: "[workflow2.m.pipedream.net](http://workflow2.m.pipedream.net)",
    method: "POST",
    data: {
      name: "Leia",
    }
  })
}
2 Likes

Dylan Sather (Pipedream) : since steps are just Node.js code, you can also modify any step to handle conditional logic within the step. For example, if you want to run one step conditionally, just click into its code and edit it to read:

if (myCondition) {
  ... original action code
}
1 Like

Dylan Sather (Pipedream) : Let me know if those options help. We’re planning to improve the way you can run steps conditionally, or even handle branching / looping, in the future

2 Likes

Hi Dylan! Can you please clarify what you mean by this? Would this also apply to pre-built actions, for example, Google Sheets > Add Single Row. Is it possible to add a condition to a pre-built action? If not, it would be a great feature to be able to add a Filter on top of an Action.

@tainguyen Thanks for reaching out. Since you have full code-level control over workflows, you can always implement conditional statements within a workflow code step.

Conditional statements / filters on pre-built action steps are coming. Please follow this GitHub issue for updates.