Skip to main content

My zap is triggered event ticket sales. There are two ticket types.

I need to sum the number of tickets purchased. These are provided in the trigger response as single items with the same ticket type name. I.e. Within a large response array each ticket appears with a quantity of 1 for each ticket purchased. ticket_class_name: Student Admission, Quantity 1.

I have been following this solution:

This solution works well to sum the number of tickets when a ticket of that type exists but if there is no ticket of that type the numbers step fails as there is no data to sum.

I tried an IF(ISBLANK spreadsheet function but the whole function is evaluated rather than ignoring the sum if ISBLANK is true, so I receive the same error.

Any idea how I can sum my ticket quantities, even if no tickets of that type were purchased?

Hi @MattBarkerNZ 

Good question.

We would need to see screenshots with how the data is returned from the app in the Zap step you are trying to use.


@Troy Tessalone Thank you. Screenshots below. The last screenshot shows what happens when there is no data present. The first few show when data is present.
 

 


@MattBarkerNZ 

Try using 1 Code step: https://zapier.com/apps/code/help

 

CONFIG

 

CODE

let QTY = inputData.QTY.split(",").map(Number);

let SUM = QTY.reduce(function (accumulator, currentValue) {
return accumulator + currentValue;
}, 0);

output = {QTY, SUM}];

 

RESULTS

 


@MattBarkerNZ 

Or you could add a ,0 between the variable and the ) to give the Formatter step 2 arguments.

 


@Troy Tessalone, the javascript runs into the same problem when there is no data. Any idea of how to handle a scenario where data is sometime not available?
 

Thank you for helping me.


@MattBarkerNZ 

If the Zap should not proceed, then add a Filter step: https://zapier.com/apps/filter/help


@MattBarkerNZ 

Or you can try this updated Code:

let SUM = 0;
let QTY = inputData.QTY || "";

if (QTY) {
QTY = QTY.split(",").map(Number);
}

if (QTY.length > 0) {
SUM = QTY.reduce(function (accumulator, currentValue) {
return accumulator + currentValue;
}, 0);
}

output = {QTY, SUM}];

 


@Troy Tessalone, I have two ticket types. One may be present while the other missing. My assumption is that a filter on one will prevent the process from proceeding with the other. i.e. if I add a filter to only proceed when there are student tickets present, any time they are absent but teacher admission tickets are present, will be filtered out.

Is that correct?

Again, thank you.


@Troy Tessalone , Oooo…. now we’re cooking! That updated JS seemed to work! Thank you so much. I will give it a few tests and then mark the response as best answer.