Up to version 14.x (included) it was possible with C/AL and AL to add a VARIANT datatype to a column in the dataset.
Since version 15.x onwards, Microsoft implemented the capability of serializing the dataset as part of the cloud printing enablement slice. This involved dataset being in need to have a specific datatype assigned. Adding a VARIANT to a dataset column would result, then, in a runtime error like the one shown below
…
Type: System.ArgumentException
Message:
Type 'System.Object' is not known to the NavSerializer.
Parameter name: typeHandle
ParamName: typeHandle
StackTrace:
at Microsoft.Dynamics.Nav.Types.Data.NavSerializer.GetTypeCode(RuntimeTypeHandle typeHandle)
at Microsoft.Dynamics.Nav.Types.Data.NavDataColumn.set_DataType(Type value)
at Microsoft.Dynamics.Nav.Types.NavDataSetBuilder.AddColumnToDataTable(MetaDataItemColumn field, NavDataTable dataTable)
at Microsoft.Dynamics.Nav.Types.NavDataSetBuilder.CreateNavDataSet(MetaReport metaReport)
…
Adding a VARIANT datatype to a column will throw an error at design time when building the package (CTRL+SHIFT+B) starting from 18.x (Dynamics 365 Business Central 2021 Wave 1).
Considering all previous versions, using AL Language Extension Build 6.1.362735 or higher
A Warning will be thrown at design time when compiling like the following
…
Microsoft (R) AL Compiler version 6.1.5.35065
Copyright (C) Microsoft Corporation. All rights reserved
Compilation started for project 'ReportVariant' containing '1' files at '12:53:15.538'.
c:\APP\ReportVariant\src\report\Rep50100.ReportVariant.al(13,41): warning AL0638: 'Variant' is not a valid column type for column 'VariantVar' in report 'ReportVariant'. This warning will become an error when targeting a runtime with version '7.0' or higher.
Compilation ended at '12:53:18.452'.
Success: The package is created.
...
Deploying such app will result in a System.ArgumentException error.
If you have some development that is using VARIANT datatype within a report column you might think of applying some of these workarounds:
- Always pass a TEXT code
- Use VB.NET code within your report to evaluate if this is a Text or Decimal value or whatever (create your own function or use CDec or IsDecimal, e.g. if you have decimal )
Another solution might be
- Add 2 different column in the dataset for Text and Decimal (or whatever)
- Add 2 – or N - textboxes with the same dimension in the same position one on top of the other and conditionally display one or the other
- Alternative to b., if this is part of Tablix lines, you might add N extra lines with conditional visibility set, depending on if this has been set to decimal or text or whatever other datatype.

Report
All responses (