I have a similar situation where I need leading zero’s in the autonumber of a table. I have fixed it with the following formula
if(row_id() < 10, concat('0000',row_id()),if(row_id() < 100,concat('000',row_id()),if(row_id() < 1000,concat('00',row_id()),if(row_id() < 10000,concat('0',row_id()),row_id()))))
In short: the formula adds leading zero’s depending on the number of digits of the row’s id