Skip to main content

I need to conditionally skip steps based on if a specific field value of multiple field values is provided or not.

 

Can I use ‘Code by Zapier’ and javascript to check if the value exists, and if it does, continue to next step (for example, Step 2) and if it does not exist, continue to a different step (for example, Step 5).

@andrenellin I so wish we could do this in Zapier, but alas that functionality is not available. 

 

There are a couple of workarounds, and it all depends on the logic you need as to which work around you choose. 

 

One workaround I do often is paths, if the data I’m manipulating needs different actions done to it or done because of it I will turn to paths.

As a bonus, if I then need to do similar steps to data after the manipulation in those paths and I don’t want to repeat myself by having the same steps in each path I will have a “part 2” zap triggered by a webhook. So at the end of each path branch, I call the webhook for part 2 and pass the data I need to that part 2 zap via the webhook. 

 

The other option which I’ve used in the past is to have x number of zaps (say for example 4) all triggering off of the same trigger (ie a new lead or a new ticket or a new invoice) all of those zaps will fire for each new trigger (a new invoice will fire those 4 zaps) and then each zap has a filter within it to determine if the trigger data is the type I want (so by territory, address, sales person etc) and then the rest of the zap continues as needed. 

 

You can combine the two options above and have webhooks at the end of those x zaps and paths within them etc. 

 

Another tool I like to use in these situations is the spreadsheet style formula (Formatter by Zapier > Numbers > Spreadsheet Style formula) Which is only designed for numbers, but if you put quotes (“”) around your values you can use the if() function to do some magical things. 

It’s kind of like a lookup table but different in that you can specify different values, and you can next logical statements. 

 

Say for example you want to use the value from field1 if field2 is Xyz and field3 is abc. However if you want to use the contents of field14 if field2 is XYZ but field3 is something else, and finally you want to use field23 if field2 is not xyz I would write up a spreadsheet-style formula similar to this (this is untested theory code, your milage may vary!) 

if("{ { field2 } }"="xyz",if("{ { field3 } }"="abc","{ { field1 } }","{ { field14 } }"),"{ { field23 } }")

And then I will use the output of that step in another step or the final step. 

Let me know what questions this brings up! Or which option you need help pursuing. 


Sorry about the nasty code formatting, I could not put two curly braces next to each other, so {} became { { field1 } }  -- annoying!


Thanks Paul. Your response is spot on and useful. Can you refer me to any resources/tutorials for passing data to the part 2  zap using webhooks.


Just wanted to follow up here to share a link to a similar thread that talks about other ways to add If/Else conditional logic to Zaps that may be useful to others looking to build a similar workflow: 


To find out more about how to pass data between Zaps using webhooks, the following resources may be a good place to start:


And depending on the use case, it may also be worth looking into using Sub-Zap by Zapier app to pass data between two different Zaps. More on that here: Build reusable Sub-Zaps :)