Add Leading 0

I need to add a leading 0 when the number is 4 digits. My results should always be 5 digits. Ex if number is 1234, should be 01234. If number is 12345, number should be 12345. 

 
I have the below script but it is not quite working. Any assistance is appreciated. Thank you!

 
function padDigits(number, digits) {
    return Array(Math.max(digits - String(number).length + 1, 0)).join(0) + number;
}

Use like:

padDigits(9, 4);  // "0009"
padDigits(10, 4); // "0010"
padDigits(15000, 4); // "15000"

use something like :

var myNum=1234;

var myPaddedNum = ("00000"+myNum).slice(-5);

myPaddedNum contains “01234”

I’ve tried running your script in chrome’s devtools and it seems to be functioning as you want it to.

If the issue is that you aren’t sure how to implement this in the datamapper then you must add an “Action” step after your extraction and add the following line to the expression box in the “Run Javascript” pane along with your function:

record.fields.#Field = padDigits(record.fields.#Field, 5);

#Field” must be the actual name of the field you wish to modify.