How to add leading zeros to a value

I am creating a .txt file with the 'File Generator Helper'. The end system requires a certain field to be 4 digits long, and contain zeros leading up to the actual value. So if the value is '1', then the output needs to be '0001'. If the value is '10', then the output needs to be '0010'. Is there a handlebar expression that can format the output to meet this requirement?

0

Comments

6 comments
Date Votes
  • Hi.  This works.  try it in the handlebars editor too. 

    {{substring (join "" "0000" name) (add name.length 4) (subtract (add name.length 4) 4)}}

     

    0
  • Probably a Regex would do it too.  

    0
  • Thanks, David. I tried this in the handlebars editor and it works when the string is a text value. But then I tried it with a numeric value and it only returned '0000'. 

    Then I tried it in the File Generator Helper and I got an error -- Expected ',' instead of '"'. 

     

    0
  • Update on this for anyone that is interested - since I am pulling the data from a saved search in NetSuite, I used the SQL expression LPAD. An example of this is: LPAD({linesequencenumber}, 4, '0'). This adds zeros to maintain 4 digits in all results. Then just passing those values through io.

    0
  • Yes, LPAD is much simpler!  

    0
  • Hi Cory, I'm sorry for the late reply, but if this is a fixed width file, have you tried using paddingChar? https://docs.celigo.com/hc/en-us/articles/360040743071-Configure-EDI-and-fixed-width-files#Header

    1

Please sign in to leave a comment.

 

Didn't find what you were looking for?

New post