Best answer

Creating a list with consecutive numbers

  • 18 February 2021
  • 7 replies
  • 741 views

Userlevel 4
Badge +4

I need to create a list with consecutive numbers. I.e.: I need the following values in one field: 
Value of a certain field + 1, Value of a certain field + 2, Value of a certain field + 3, Value of a certain field + 4 etc.

So if the field has a value of 10 the results would be: 
11, 12, 13, 14 etc.

What’s the best way to get these numbers? I was wondering if the “Spreadsheet-style formula functions” or a Python script in Zapier would be the best way to do this. 

Thanks for help.

icon

Best answer by Troy Tessalone 20 February 2021, 19:13

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.

7 replies

Userlevel 7
Badge +14

Hi @michael291 

Both options would work, but the Code step will save Tasks.

Userlevel 4
Badge +4

Hi @Troy Tessalone thanks! Do you have an example for that? I am not so experienced with Python and I already took a look on Google but couldn’t find anything similar.  

Thanks for help

Userlevel 7
Badge +11

Hi @michael291!

Here’s a bit of a hack-y way to do it but it works :) Not sure how any times you have to add to that value but you can use Google Sheets like this:

Then you will get each of those values in the output of this step:

This is mostly because I’m not that great with code, so I find ways around it 😛 

Userlevel 7
Badge +14

@michael291 

You could also use this Formatter > Numbers > Perform Math Operation > Add step

 

Userlevel 4
Badge +4

@nicksimard Thanks, but I thought there would be a solution without Google Sheet (i.e. doing a Spreadsheet-style formula etc.). 

 

@Troy Tessalone I had that before. But I needed 9 single steps to get 10 consecutive numbers (based on the first number). I.e. 9 (is the base) and the following numbers 10, 11, 12 etc. So I thought there would be a solution with Python or a Spreadsheet-style formula to save a few steps within the Zap. 

 

Userlevel 7
Badge +14

@michael291 

Give this Code a try...

 

Returns

 

Userlevel 4
Badge +4

Hi @Troy Tessalone you are great!!! I owe you three beer for that. Absolutely perfect!!

 

That’s even better what I was looking for. I have added your JavaScript code snippet below for other people who are interested in it… 

 

 

 

Here’s the code snippet of the JavaScript… 

 

var INPUT = parseInt(inputData.INPUT); // sets variable value as a number
var INCREMENT = parseInt(inputData.INCREMENT); // sets variable value as a number
var BASE = parseInt(inputData.BASE); // sets variable value as a number
var COUNT = parseInt(inputData.COUNT); // sets variable value as a number
var RESULT = []; // defines an empty array

while (BASE <= COUNT) // sets conditions for loop to execute while condition is true
{
INPUT = INPUT + INCREMENT; // increments value each time
RESULT.push(INPUT); // adds new value to array
BASE = BASE + INCREMENT; // increments value each time
}

RESULT = RESULT.join(); // converts array to comma separated string
output = [{RESULT}]; // returns specified variables