Best answer

Building a workflow with multiple "if" conditions that can run concurrently

  • 14 August 2019
  • 4 replies
  • 1851 views

Originally asked by @IgniteMarketing:

There are multiple “ifs” possibilities, where we’ll want to do additional actions depending on data received on a form. What’s the best way to set it up? A simple filter would cause it to end too early if a certain if fails but I need to do another.

Paths are a potential option, but can multiple paths trigger at once?



icon

Best answer by BowTieBots 21 August 2019, 16:19

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

4 replies

Userlevel 7
Badge +9

Yes! Multiple Paths can run at once as long as the criteria for each is met.

@BowTieBots set this up with a Code step that sends a fetch to Zapier webhook triggers depending on the if the results. This makes modifications easier as you don’t break a string of paths if you make a change and there is more flexibility and error handling that can be put into coded steps. I'll default to Richard here to explain his setup further.


Userlevel 4
Badge +4

Here is the basics of how I run a looped trigger that will perform multiple tasks and act as path filters. I use this pattern for a lot of different use cases so I tried to keep this at a high level overview. The code steps can be modified to achieve what ever you want. The keys to successfully make it work are sending the JSON object wrapped in array for formatting and set-up logic for the zaps to loop until finished.

From a task perspective you will use an additional 3 tasks per loop over the building something using strict paths but you will gain ease of modification and maintenance.

Looping Data.pdf The two code steps are as follows:

Code Step (1):

/**Initial Code step builds the data object

* Validates and augments any incoming data

* Returns an obj for looping if applicable, the obj length, and an output for any formatted data

*/

 

var data = inputData.datasplit('~'), //Assumes data comes in on one line with data points seperated by '~'

obj = {

valueOne: data[0],

},

output = {},

url= '';

 

/**

**Add any data validation you need here

*/

 

/**

**Build your output here.

* output = {

* 1: {},

* 2: {},

* }

*/

 

var count = 1;

for(var x=1; x < data.length; x++){ //Starting at one ignores the values being used for the current zap

output[count]={

valueOne: data[x]

};

 

count++

}

 

/**You can do a data validation with if statements and set the url to a different loop

** If(obj.valueOne.indexOf('filterValue')> -1){

url= ''

} else {url = ''}

*/

 

 

 

return {

obj: obj, //These are the variables you will be using in the Zap function

data: JSON.stringify(output), //Thiss will be passed to the loop function to continue taking action on the data

length: count, //This value determines if the looping the data is required. A count value greater than 0 means looping is required.

url: 'webhook.zapier.com' //Webhook output for the next step if needed

 

}

 

Code Step (2):

/**Secendary code steps parse the obj,

* Remove the next set of data from the the object

* Return an obj for looping if applicable, obj length, and an output for the formatted data

*/

var data = JSON.parse(inputData.data), /

obj = {

valueOne: data['1']['valueOne'],

},

output = {};

 

/**

**Add any data validation you need here

*/

 

/**

**Delete the One value in the data object and then rebuild the output

*/

 

delete data['1'];

 

var count = 1;

for(var x in data){

output[count]={

valueOne: data[x]['valueOne'];

};

 

count++

}

 

 

 

return {

obj: obj, //These are the variables you will be using in the Zap function

data: JSON.stringify(output), //This will be passed to the loop function to continue taking action on the data

length: count, //This value determines if the looping the data is required. A count value greater than 1 means looping is required.

 

}

 

Userlevel 5

Sweet, @BowTieBots! Thanks for sharing this! I haven't run across the need for something like this, but now my head is spinning just thinking about the possibilities it opens up! 🤔


Userlevel 5

Just coming back by to thank @BowTieBots for sharing this plan of attack and the code sample. I've already incorporated it into a project where this gave me a more direct route than the long way around that I would've probably gone. Seriously: thank you! (And thank you, @jesse, for helping surface this for the community!)