Best answer

Zap is unable to sum ticket quantities when no tickets were purchased.

  • 24 October 2023
  • 9 replies
  • 56 views

Userlevel 1

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?

icon

Best answer by Troy Tessalone 24 October 2023, 22:20

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.

9 replies

Userlevel 7
Badge +14

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.

Userlevel 1

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

 

Userlevel 7
Badge +14

@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

 

Userlevel 7
Badge +14

@MattBarkerNZ 

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

 

Userlevel 1

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

Userlevel 7
Badge +14

@MattBarkerNZ 

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

Userlevel 7
Badge +14

@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}];

 

Userlevel 1

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

Userlevel 1

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