Business Central 2023 wave 2 (BC23): New supported types for Variant Data Type – List Data Type and Dictionary Data Type

Dynamics 365 Business Central

Hi, Readers.
The public preview for Dynamics 365 Business Central 2023 release wave 2 (BC23) is available. Learn more: Link.

I will continue to test and share some new features that I hope will be helpful.

In this post, I would like to talk about New supported types for Variant – List, Dictionary. This is not yet documented in the Business Central 2023 release wave 2 (BC23) release plan. But it is mentioned in AL Language extension changelog Version 12.

It is now possible to assign List and Dictionary to a Variant. The Variant type has been augmented with two new properties IsList and IsDictionary to allow for detecting if it contains the relevant types.

https://marketplace.visualstudio.com/items/ms-dynamics-smb.al/changelog

Let’s see more details.

Variant Data Type: Represents an AL variable object. The AL variant data type can contain many AL data types.
This is helpful when you are not sure what data type of value is being transferred, or want to handle it differently depending on the data type.
For example, in base application:
codeunit 1173 “Document Attachment Mgmt”:

codeunit 10 “Type Helper”:

In this wave, it is possible to assign List and Dictionary to a Variant.

List Data Type: Represents a strongly typed list of ordered objects that can be accessed by index. Contrary to the Array data type, a List is unbounded, such that its dimension does not need to be specified upon declaration.

Dictionary Data Type: Represents an unordered collection of keys and values. The Dictionary data type is optimized for fast lookup of values.

The Variant type has been augmented with two new properties IsList and IsDictionary to allow for detecting if it contains the relevant types.

procedure IsList(): Boolean
Indicates whether an AL variant contains a List variable.

procedure IsDictionary(): Boolean
Indicates whether an AL variant contains a Dictionary variable.

A simple example:

Test code:

pageextension 50112 MyExtension extends "Customer List"
{
    trigger OnOpenPage()
    var
        VariantList: List of [Integer];
        VariantDictionary: Dictionary of [Integer, Text];
        MyVariant: Variant;
        Result: Boolean;
        Text000: Label 'Does the variant contain an List variable? %1.';
        Text001: Label 'Does the variant contain a Dictionary variable? %1.';
    begin
        MyVariant := VariantList;
        Result := MyVariant.IsList;
        Message(Text000, Result);
        MyVariant := VariantDictionary;
        Result := MyVariant.IsDictionary;
        Message(Text001, Result);
    end;
}

Great. Give it a try!!!😁

PS:
1. In previous versions:

2. The following methods are available on instances of the Variant data type.

Method nameDescription
IsAction()Indicates whether an AL variant contains an Action variable.
IsAutomation()Indicates whether an AL variant contains an Automation variable.
IsBigInteger()Indicates whether an AL variant contains a BigInteger variable.
IsBinary()Indicates whether an AL variant contains a Binary variable.
IsBoolean()Indicates whether an AL variant contains a Boolean variable.
IsByte()Indicates whether an AL variant contains a Byte data type variable.
IsChar()Indicates whether an AL variant contains a Char variable.
IsClientType()Indicates whether an AL variant contains a ClientType variable.
IsCode()Indicates whether an AL variant contains a Code variable.
IsCodeunit()Indicates whether an AL variant contains a Codeunit variable.
IsDataClassification()Indicates whether an AL variant contains a DataClassification variable.
IsDataClassificationType()Indicates whether an AL variant contains a DataClassification variable.
IsDate()Indicates whether an AL variant contains a Date variable.
IsDateFormula()Indicates whether an AL variant contains a DateFormula variable.
IsDateTime()Indicates whether an AL variant contains a DateTime variable.
IsDecimal()Indicates whether an AL variant contains a Decimal variable.
IsDefaultLayout()Indicates whether an AL variant contains a DefaultLayout variable.
IsDotNet()Indicates whether an AL variant contains a DotNet variable.
IsDuration()Indicates whether an AL variant contains a Duration variable.
IsExecutionMode()Indicates whether an AL variant contains an ExecutionMode variable.
IsFieldRef()Indicates whether an AL variant contains a FieldRef variable.
IsFile()Indicates whether an AL variant contains a File variable.
IsFilterPageBuilder()Indicates whether an AL variant contains a FilterPageBuilder variable.
IsGuid()Indicates whether an AL variant contains a Guid variable.
IsInStream()Indicates whether an AL variant contains an InStream variable.
IsInteger()Indicates whether an AL variant contains an Integer variable.
IsJsonArray()Indicates whether an AL variant contains a JsonArray variable.
IsJsonObject()Indicates whether an AL variant contains a JsonObject variable.
IsJsonToken()Indicates whether an AL variant contains a JsonToken variable.
IsJsonValue()Indicates whether an AL variant contains a JsonValue variable.
IsNotification()Indicates whether an AL variant contains a Notification variable.
IsObjectType()Indicates whether an AL variant contains an ObjectType variable.
IsOption()Indicates whether an AL variant contains an Option variable.
IsOutStream()Indicates whether an AL variant contains an OutStream variable.
IsRecord()Indicates whether an AL variant contains a Record variable.
IsRecordId()Indicates whether an AL variant contains a RecordId variable.
IsRecordRef()Indicates whether an AL variant contains a RecordRef variable.
IsReportFormat()Indicates whether an AL variant contains a ReportFormat variable.
IsSecurityFiltering()Indicates whether an AL variant contains a SecurityFiltering variable.
IsTableConnectionType()Indicates whether an AL variant contains a TableConnectionType variable.
IsTestPermissions()Indicates whether an AL variant contains a TestPermissions variable.
IsText()Indicates whether an AL variant contains a Text variable.
IsTextBuilder()Indicates whether an AL variant contains a TextBuilder variable.
IsTextConstant()Indicates whether an AL variant contains a Text constant.
IsTextEncoding()Indicates whether an AL variant contains a TextEncoding variable.
IsTime()Indicates whether an AL variant contains a Time variable.
IsTransactionType()Indicates whether an AL variant contains a TransactionType variable.
IsWideChar()Indicates whether an AL variant contains a WideChar variable.
IsXmlAttribute()Indicates whether an AL variant contains an XmlAttribute variable.
IsXmlAttributeCollection()Indicates whether an AL variant contains an XmlAttributeCollection variable.
IsXmlCData()Indicates whether an AL variant contains an XmlCData variable.
IsXmlComment()Indicates whether an AL variant contains an XmlComment variable.
IsXmlDeclaration()Indicates whether an AL variant contains an XmlDeclaration variable.
IsXmlDocument()Indicates whether an AL variant contains an XmlDocument variable.
IsXmlDocumentType()Indicates whether an AL variant contains an XmlDocumentType variable.
IsXmlElement()Indicates whether an AL variant contains an XmlElement variable.
IsXmlNamespaceManager()Indicates whether an AL variant contains an XmlNamespaceManager variable.
IsXmlNameTable()Indicates whether an AL variant contains an XmlNameTable variable.
IsXmlNode()Indicates whether an AL variant contains an XmlNode variable.
IsXmlNodeList()Indicates whether an AL variant contains an XmlNodeList variable.
IsXmlProcessingInstruction()Indicates whether an AL variant contains an XmlProcessingInstruction variable.
IsXmlReadOptions()Indicates whether an AL variant contains an XmlReadOptions variable.
IsXmlText()Indicates whether an AL variant contains an XmlText variable.
IsXmlWriteOptions()Indicates whether an AL variant contains an XmlWriteOptions variable.

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL