Leading zeros in parameter

0
Hello, I need to add a flexible amount of text (leading zeros) to a input. So f.i. input ‘666’ would become ‘0000666’ in case of a desired input of 7 characters. In case of 4 characters it would become '0666’. How to accomplish that?
asked
3 answers
4

Use the StringLeftPad Java action from the CommunityCommons module

answered
3

Use

substring($Zeros,0,$DesiredLengthValue-length($ValueWithoutLeadingZeros) )+$ValueWithoutLeadingZeros

where:

- $ValueWithoutLeadingZeros is a string with the original value without trailing zeros
- $Zeros is a string with at least the amount of zeros for the maximum length of the value including trailing zeros (e.g. '000000000000000000000')
- $DesiredLengthValue is an integer with the Desired length of the desired value including trailing zeros

answered
-2

Hi Ad,

You could do this in an ‘On Change’ microflow or in your safe action.

use length() to check the length of the input (use toString() first if the input attribute is an Integer), and just add 0s to achieve your desired length ( if $length = 5 then '00’+$input else if length= … etc)

answered