Leading Zero with Basic Math

I'm using a table and have a distinct column for rowIndex (in addition to the build in rowIndex) that is in the format 01, 02, 03, 04. With each new form submitted, we need to add +1 to the existing highest number in the table. I'm using a combination of Tables: Get maximum data in a column + Numbers: Perform basic math actions. When I do this, the leading zero is dropped. Is there a way to still do the +1 math but avoid dropping off the leading 0?

Tagged:

Best Answer

  • Meghan_550057Meghan_550057 Posts: 105
    edited August 7 Accepted Answer

    Used a variation of @Thomas_937381's suggestion with a Field: Field Formulas action to retain leading 0s and add +1. To use this, replace max-row-data with your field name.

    var next = (parseInt(fields["max-row-data"]) + 1)
    if (next <= 9) {
    result = "0".concat(next.toString()) }
    else {
    result = next }
    

Answers

  • Thomas_937381Thomas_937381 Posts: 196

    @Meghan_550057 If you have that value as a field, I think something like this might work. You may have to check my syntax. ;)

    var next = (Math(parseInt(fields["index"]) + 1))
    if (next <= 9) {
    result = "0".concat(next.toString()) }
    else {
    result = next }
    

    Hope this helps! This thread may also be helpful here.

Sign In or Register to comment.