With the release of Business Central 2025 Wave 1, Business Central continues to simplify AL development by introducing intuitive and developer-friendly features. One such small yet powerful enhancement is the ToText
method — designed to streamline how simple type values are converted to text.
In previous versions, we developers often relied on FORMAT()
for converting simple types like integers, decimals, booleans, and option values into text. While FORMAT()
has been effective, it comes with localization considerations and sometimes produces inconsistent results depending on the environment or the formatting settings.
ToText
MethodThe new ToText
method is a type extension method introduced for simple AL types. It provides a clearer, more consistent way to convert values to string representations without the overhead of full formatting logic.
The ToText
method supports the following simple types:
Integer
Decimal
Boolean
Char
Option
Date
Time
DateTime
GUID
Let’s look at some examples of how the ToText()
method can simplify your code:
var
myInteger: Integer := 42;
myDecimal: Decimal := 2.71828;
myDate: Date := TODAY;
myTime: Time := TIME(10, 30, 0);
myBoolean: Boolean := true;
myOption: Option Alpha,Beta,Gamma := Option::Beta;
integerAsText: Text;
decimalAsText: Text;
dateAsText: Text;
timeAsText: Text;
booleanAsText: Text;
optionAsText: Text;
begin
integerAsText := myInteger.ToText(); // integerAsText will be '42'
decimalAsText := myDecimal.ToText(); // decimalAsText will be '2.71828' (or similar based on locale)
dateAsText := myDate.ToText(); // dateAsText will be the default short date format
timeAsText := myTime.ToText(); // timeAsText will be the default time format
booleanAsText := myBoolean.ToText(); // booleanAsText will be 'true'
optionAsText := myOption.ToText(); // optionAsText will be 'Beta'
Message('Integer: %1', integerAsText);
Message('Decimal: %1', decimalAsText);
Message('Date: %1', dateAsText);
Message('Time: %1', timeAsText);
Message('Boolean: %1', booleanAsText);
Message('Option: %1', optionAsText);
end;
FORMAT
Feature | FORMAT() |
ToText() |
---|---|---|
Localization | Locale-dependent | Locale-independent |
Use Case | Complex formatting, reports | Simple value conversion |
Readability | Verbose | Minimal & concise |
Output Format | Varies by user settings | Consistent, type-based |
Prefer ToText()
when you want predictable results across environments (e.g., when storing values in logs or metadata).
Continue using FORMAT()
when you need locale-aware output, such as in printed documents or user-facing formatted messages.
It simplifies the process of converting simple data types to their default text representations, leading to cleaner, more readable, and potentially more efficient code. While FORMAT()
remains the go-to for advanced formatting needs, ToText()
will undoubtedly become a frequently used tool in your Business Central development.
Stay tuned for more…