Google Apps Script - Please help me, I am having trouble with Google Apps Script. I was making an order entry ID in Google Sheets but to create a neat ID with uniform length of digits, I figured I need to repeat a string of '0' a number of times before an auto increment number in google sheets (set a fixed length of digits for the ID like 1,2...5...10 would be 0001,0002...0005...0010)
So far I have the auto-incrementing number function working fine already, it is just the repeating '0' function that doesn't
This is the code:
function onFormSubmit(e)
{
var sheet = SpreadsheetApp.getActiveSheet();
var row = SpreadsheetApp.getActiveSheet().getLastRow();
var tally = sheet.getRange("AG2").getValue();
tally++;
sheet.getRange(row,2).setValue(tally);
sheet.getRange("AG2").setValue(tally);
*\\above is the code for the auto incrementing ID numbers*
if (tally.length<4)
{
sheet.getRange(row,2).setValue('0'.repeat(4-tally.length), tally);
}
*\\this is supposedly the code for setting up a fixed length of 4 digits for
the ID but i was assuming that a javascript's: 'string'.repeat should work on
google script.*
}
This, however, doesn't work so the output is still an incrementing ID number for every form submitted but the digits length is not fixed to 4 digits so I was getting 1,2,3...10,11 instead.