Fix the input data to fix value

0
Hi guys, Anyone know how to make the input data to specific fix value. Can I set to auto 4 digit for lot number? If user just key in 614, the result will be 0614. I am using string as object type. Below is the example:
asked
2 answers
0

Solution1: If you already have CommunityCommons imported into your project: use java-action StringLeftPad.

Otherwise, solution2: you can do this in a microflow by adding activity ‘Change variable’

substring(toString(10000+parseInteger($YourObject/FourCharAttribute)),1,4)

Surround this with a check if the value contains only digits, to prevent parseInteger throwing an error.

Or solution 3: simply some ifs adding ‘0’, ‘00’, ‘000’, or ‘0000’

     if(length($YourObject/FourCharAttribute)=4) then $YourObject/FourCharAttribute
else if(length($YourObject/FourCharAttribute)=3) then ('0'+$YourObject/FourCharAttribute)
else if(length($YourObject/FourCharAttribute)=2) then ('00'+$YourObject/FourCharAttribute)
else if(length($YourObject/FourCharAttribute)=1) then ('000'+$YourObject/FourCharAttribute)
else '0000'

 

Consider adding your check as a validation rule on the attribute of your entity.

answered
0

If the user is entering the numbers to an input widget, you can define an input mask so that the user is forced to always enter 4 digits.

How this works is described in the Input Mask section of the following page:

https://docs.mendix.com/refguide/text-box

Otherwise, you could also create a java action that adds “0” characters depending on the length of the string.

answered