Hi All,
I have some questions about how to add/generate leading zeros infront of existing value (integer value).
I have a field in my form that will be saved into entity as well. It is a text data type variable, but the data/value for this variable is actually combination of characters and digits e.g. AA00001 (format is first 2 chars and followed by 5 digits).
My issue is, I have to auto increment the running digits behind the first 2 chars, which is in this case: 00001. And, whenever I split the text (AA00001) into 2 parts and use IntegerToText( TextToInteger(xxx) ) function on the digits before concat the digits(00002) to the characters in front, it will become only the number added without leading zeros. It became AA2. The ideal/wanted outcome is AA00002.
Hi Junior,
You can use FormatText built-in function: https://success.outsystems.com/Documentation/11/Reference/OutSystems_Language/Logic/Built-in_Functions/Format#FormatText
For example: This will output 00001
FormatText(1,5,5,True,"0")
Regards,
Khuong
Hello Junior,
By definition, an Integer field (or any other field designed to store numeric values like Currency) cannot be used to store or represent non-significant digits like leading zeros.
Going over your usecase, I assume that both the letters and the digit for your variable are deterministic - that is, you can calculate the final result of your variable at any point by looking at the rest of your data, without input from your user. If this is the case, I'd keep both an Integer field holding the digit value (to make it easier to increment it during any calculations or if you need to determine the maximum value in your Entity), as well as a Text field holding the final variable (AA00002) in the Entity representing your form.
Keeping the component fields of your variable separate means you only have to split the text once to obtain both components of your variable, reducing your calculations. For the final requirement of the leading zeros, you can use FormatText like Khuong indicated.