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",
    }
  })
}
3 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

3 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.

1 Like

I am interested in this solution, but it seems to imply that I can take any pre-built step (say, a Post to Discord step) and edit its code in javascript so I can wrap it in a conditional? If so I don’t see how I can go inside the code of any given step.

The idea of triggering separate subsequent workflows as part of the conditional seems ridiculous, as it would effectively double the invocation cost of any workflow.

This webhook approach is fine… but it eats up a lot of workflows quickly. Maybe that’s part of the business model. I’m perfectly willing to buy the Basic plan to make my own life and productivity a little easier but I can easily run through all 20 active workflows with this approach and I can’t justify Advanced pricing just to get my todo list to work exactly the way I want it to.

1 Like

I was turning away from Zapier because there is lack of built-in flow control and I will do now.