Convert Simple Type Values to Text Using the New ToText Method in Business Central 2025 Wave 1

Amol SalviBusiness Central13 hours ago23 Views

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.

✨ What’s New: ToText Method

The 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.

Supported Types

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;

🔄 Difference from 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…

Original Post https://ammolhsaallvi.blog/2025/04/25/convert-simple-type-values-to-text-using-the-new-totext-method-in-business-central-2025-wave-1/

0 Votes: 0 Upvotes, 0 Downvotes (0 Points)

Leave a reply

Join Us
  • X Network2.1K
  • LinkedIn3.8k
  • Bluesky0.5K
Support The Site
Events
April 2025
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30     
« Mar   May »
Follow
Sign In/Sign Up Sidebar Search
Popular Now
Loading

Signing-in 3 seconds...

Signing-up 3 seconds...