In AL development for Microsoft Dynamics 365 Business Central, helper code units are a foundational design pattern used to encapsulate reusable logic. These code units act as modular libraries that simplify your main business logic by offloading common tasks, such as formatting, validation, or calculations, into clean, callable units. Let’s take a look at one of the most useful helper code units; Type Helper.
The Type Helper code unit in Microsoft Dynamics 365 Business Central is a powerful utility designed to assist with data formatting, localization, and type conversion tasks. There are also several math function included in the library as they are useful in API handling which is a common use case for this library.
Type Helper is part of the System.Reflection namespace. You will need to include a “using System.Reflection;” statement in your code. You can then create the Type Helper as a variable like this:
TypeHelper: Codeunit "Type Helper";
There are 74 procedures, and 2 obsolete procedures, in this super powerful code unit. Here is a brief breakdown of each procedure.
- Evaluate
Evaluates a string value into a Variant variable, supporting Date, DateTime, Decimal, and Integer types with optional format and culture. - GetLocalizedMonthToInt
Converts a localized month name (e.g., “January”) to its corresponding integer (1-12). - CompareDateTime
Compares two DateTime values, returning 1, 0, or -1 depending on their relationship, with a small threshold for equality. - FormatDate (Date, LanguageId)
Formats a Date value according to a specified language ID. - FormatDate (Date, Format, CultureName)
Formats a Date value using a custom format string and culture name. - FormatDateWithCurrentCulture
Formats a Date using the current user’s culture. - GetHMSFromTime
Extracts hours, minutes, and seconds from a Time value. - IsLeapYear
Determines if a given Date falls in a leap year. - GetOptionNo
Returns the index of a value in an option string. - GetOptionNoFromTableField
Gets the option index for a value from a specific table field. - GetNumberOfOptions
Returns the number of options in an option string. - OptionsAreEqual
Checks if two option values are considered equal. - IsNumeric
Checks if a text value can be evaluated as a decimal number. - GetField
Retrieves a Field record for a given table and field number, if not obsolete. - GetFieldLength
Returns the length of a field in a table. - TestFieldIsNotObsolete
Throws an error if a field is marked as obsolete. - IsPhoneNumber
Validates if a text value matches a phone number pattern. - GetUserTimezoneOffset
Gets the current user’s timezone offset as a duration. - GetUserClientTypeOffset
Gets the timezone offset if the client type is Web. - GetTimezoneOffset
Gets the timezone offset for a specified timezone ID. - EvaluateUnixTimestamp
Converts a Unix timestamp (seconds since 1970-01-01) to a DateTime, adjusted for user timezone. - EvaluateUTCDateTime
Evaluates a UTC DateTime string into a DateTime variable. - FormatDateTime
Formats a DateTime value using a format string and culture. - FormatUtcDateTime
Formats a DateTime as a string in UTC using a specified format and culture. - GetCurrUTCDateTime
Returns the current UTC DateTime. - GetCurrUTCDateTimeAsText
Returns the current UTC DateTime as a formatted string. - GetCurrUTCDateTimeISO8601
Returns the current UTC DateTime as an ISO 8601 string. - AddHoursToDateTime
Adds a specified number of hours to a DateTime. - FormatDecimal
Formats a decimal value as a string using a format and culture. - UrlEncode
URL-encodes a text value. - UrlDecode
URL-decodes a text value. - HtmlEncode
HTML-encodes a text value. - HtmlDecode
HTML-decodes a text value. - JavaScriptStringEncode (Value: Text)
Encodes a string for safe use in JavaScript. - JavaScriptStringEncode (Value: Text; AddDoubleQuotes: Boolean)
Encodes a string for JavaScript, optionally adding double quotes. - UriEscapeDataString
Escapes a string for use in a URI. - UriGetAuthority
Gets the authority part of a URI. - GetKeyAsString
Returns a comma-separated string of key field names for a record variant and key index. - ReadAsTextWithSeparator
Reads an InStream as text, joining lines with a specified separator. - TryReadAsTextWithSeparator
Tries to read an InStream as text with a separator, returns success/failure. - TryReadAsTextWithSepAndFieldErrMsg
Tries to read an InStream as text, showing a message if it fails. - CRLFSeparator
Returns a CRLF (carriage return + line feed) separator. - LFSeparator
Returns a LF (line feed) separator. - SortRecordRef
Sorts a RecordRef by specified fields in ascending or descending order. - TextDistance
Calculates the Levenshtein distance (edit distance) between two text strings. - NewLine
Returns the system’s newline string. - GetMaxNumberOfParametersInSQLQuery
Returns the maximum number of parameters allowed in a SQL query (2100). - BitwiseAnd
Performs a bitwise AND operation on two integers. - BitwiseOr
Performs a bitwise OR operation on two integers. - BitwiseXor
Performs a bitwise XOR operation on two integers. - GetFormattedCurrentDateTimeInUserTimeZone
Returns the current date/time in the user’s timezone, formatted as specified. - GetCurrentDateTimeInUserTimeZone
Returns the current date/time in the user’s timezone as a DateTime. - GetInputDateTimeInUserTimeZone
Converts a DateTime from UTC to the user’s timezone. - ConvertDateTimeFromUTCToTimeZone
Converts a DateTime from the current client timezone to a specified timezone. - ConvertDateTimeFromInputTimeZoneToClientTimezone
Converts a DateTime from a specified timezone to the current client timezone. - IntToHex
Converts an integer to a hexadecimal string. - Maximum
Returns the maximum of two decimal values. - Minimum
Returns the minimum of two decimal values. - TransferFieldsWithValidate
Transfers field values from a temporary buffer to a target record, validating changes. - CalculateLog
Calculates the base-10 logarithm of a decimal number. - GetAmountFormatLCYWithUserLocale
Returns the amount format for the local currency using the user’s locale. - GetAmountFormatLCYWithUserLocale (DecimalPlaces: Integer)
Returns the amount format for the local currency with specified decimal places. - GetAmountFormatWithUserLocale (CurrencySymbol: Text[10])
Returns the amount format for a currency symbol using the user’s locale. - GetAmountFormatWithUserLocale (CurrencySymbol: Text[10]; DecimalPlaces: Integer)
Returns the amount format for a currency symbol with specified decimal places and user’s locale. - GetAmountFormat (LocaleId: Integer; CurrencySymbol: Text[10])
Returns the amount format for a locale and currency symbol. - GetAmountFormat (LocaleId: Integer; CurrencySymbol: Text[10]; DecimalPlaces: Integer)
Returns the amount format for a locale, currency symbol, and decimal places. - GetAmountFormatDecimalPlaces
Returns the amount format for a locale, currency symbol, and decimal places, considering currency position. - GetDefaultAmountFormat
Returns the default amount format string. - GetDefaultAmountFormat (DecimalPlaces: Integer)
Returns the default amount format string with specified decimal places. - GetXMLAmountFormatWithTwoDecimalPlaces
Returns the XML amount format with two decimal places. - GetXMLDateFormat
Returns the XML date format string. - CopyRecVariantToRecRef
Copies a record variant to a RecordRef. - IsDigit
Checks if a character is a digit. - IsUpper
Checks if a character is uppercase.
Now, you might not feel like a “bitwise and” function is something you need in your ERP platform. However, there are API’s and such that may require these functions for data handling, and I’m grateful to have them when needed.
If this is looking a lot like the type helper classes found in .NET Reflection, that is because it is. Business Central AL code compiles into .NET code on the server. We can’t use all the .NET libraries, but the kind developers at Microsoft have provided these functions to help us.
More details on Learn.Microsoft.com Code unit “Type Helper” | Microsoft Learn
We will see these helper procedures appear as we start delving into API handling and other advanced software topics. Let me know if you have used these before, and what applications you use them for.





Leave a comment