Skip to main content
Best answer

Using row number as ID but must be 3 digits starting at 001


I have a trigger, when a new spreadsheet row is added. I take the row number (start at 2) because of the header. So the first value should be 2.

A format step will MINUS 1 from the Row number - giving me 1. This is the fist row after the column header.

 

But I need to format the number to 3 digits, like 001.

When it hits 10, it the value should be 010, then 100 and so on.

 

Any ideas? Thank you!

Best answer by ikbelkirasan

@Merci - This can be done easily with a Code step. Here is the code:

const rowNumber = String(+inputData.rowNumber).padStart(3, "0");
output = [{ rowNumber }];

 

View original
Did this topic help you find an answer to your question?
This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

5 replies

ikbelkirasan
Forum|alt.badge.img+12
  • Zapier Expert
  • 555 replies
  • Answer
  • July 7, 2020

@Merci - This can be done easily with a Code step. Here is the code:

const rowNumber = String(+inputData.rowNumber).padStart(3, "0");
output = [{ rowNumber }];

 


  • Author
  • Beginner
  • 3 replies
  • July 7, 2020
ikbelkirasan wrote:

@Merci - This can be done easily with a Code step. Here is the code:

 const rowNumber = String(+inputData.rowNumber).padStart(3, "0");
output = [{ rowNumber }];

 

Thanks! However, I need the 1st row after the column header to be ROW 001. Can you code MINUS 1 or should I add a format step?


ikbelkirasan
Forum|alt.badge.img+12
  • Zapier Expert
  • 555 replies
  • July 7, 2020

@Merci - Sure, you can do it in the same code:

const rowNumber = String(+inputData.rowNumber - 1).padStart(3, "0");
output = [{ rowNumber }];

 


  • Author
  • Beginner
  • 3 replies
  • July 8, 2020

Thanks for the solution again. I looked at adding data to Google Sheets and formatting the Row number into 3 digits, but your solution is much more streamline for Zapier. If you’re interested, you can find it here: 

https://docs.google.com/spreadsheets/d/1oAtDLo2Bk-3SaUAYX9GrscC6DN_h8lO8pqLUWPTAoJw/edit?usp=sharing

A2 =ARRAYFORMULA(IF(B2:B="",,TEXT(ROW(data!A1:A), "000")))
B2 =ARRAYFORMULA(data!A2:B)

 


ikbelkirasan
Forum|alt.badge.img+12
  • Zapier Expert
  • 555 replies
  • July 8, 2020

@Merci - Great, thanks for sharing!