Skip to main content

How to add leading zeros to a value

Comments

6 comments

  • Matt Graney VP of Product Management
    Answer Pro
    Top Contributor

    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
  • David Gollom Channel Partner
    Celigo University Level 4: Legendary
    Answer Pro
    Great Answer
    Engaged

    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
  • David Gollom Channel Partner
    Celigo University Level 4: Legendary
    Answer Pro
    Great Answer
    Engaged

    Probably a Regex would do it too.  

    0
  • Cory Anderson NetSuite Integration Whiz
    Engaged
    Celigo University Level 4: Legendary
    Awesome Follow-up
    Amazon-NetSuite IA Certification

    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
  • Cory Anderson NetSuite Integration Whiz
    Engaged
    Celigo University Level 4: Legendary
    Awesome Follow-up
    Amazon-NetSuite IA Certification

    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
  • David Gollom Channel Partner
    Celigo University Level 4: Legendary
    Answer Pro
    Great Answer
    Engaged

    Yes, LPAD is much simpler!  

    0

Please sign in to leave a comment.