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