App Script Padding For Child Records Numbers
I've been practicing with Apps Scripts and creating multiple child records.
From the documentation (see below), each child record will be created and numbered incrementally from 1 to the total number of records created (1 to 5).
QUESTION: How do you pad the sequence number as 01, 02, 03... instead of 1, 2, 3.
This is so column sorting is correct when more than 10 records exist.
Thanks
How do I create child records ?
// Create 5 child records
(1..5).each {
addChild “Child Table”, “Link to Parent”, [‘Status’ : ‘Active’, ‘Index’ : it ]
}

2 comments
-
John McGarvey commented
Thanks Alex - I'm just getting some time to look at this again.
I tested, but not seeing padded numbers - no errors, just nothing happening. -
Alex commented
Hi John,
You can pad the numbers using the script below:
String numberAsString = String.format ("%05d", number)
Having said that, numbers can only be padded with a leading zero if they are being stamped into a single line field and are treated as text. This also applies to the sort since text is sorted alphanumerically. This causes 1 and 10 to come before 2. If it is just stamping the children with the number, placing them into a number field will honor the intended sort of 1 to 20 without 10 coming before 2.
Hope this helps!
Alex