Showing posts with label set. Show all posts
Showing posts with label set. Show all posts

Monday, July 7, 2025

Packing Sets, Maps, Lists, etc. in D365FO: Why con2str can break your code

While working on what seemed like a routine task in Dynamics 365 Finance and Operations, I encountered an unexpected issue Specified cast is not valid when passing a Set as a parameter to a method. 


Here's what happened.

I had a simple and logical flow:

1. Pack a set or a list into a container with standard pack method.



2. Convert this container into a string with con2str global function.


3. Pass it to my function as an argument. (not depicted)

4. Convert this string back to a container via str2con.



5. Create a new set from the restored container via set create method.

Everything worked fine—until step 5.

Instead of a smooth reconstruction of the Set, I ran into an error. The root cause? The str2con() function. By default, str2con() interprets numeric values as Int64 (long integers). This silent type coercion corrupted the data structure expected by Set.create(), which led to the failure.


To avoid this issue altogether, do not use str2con() to restore containers that will be used for object reconstruction (like sets, maps, etc.). Instead, use:

  • con2base64str() to serialize the container

  • base64str2con() to safely deserialize it

These Global functions preserve the data types and internal structure of the container without any implicit type conversions.

Monday, April 10, 2017

AIF Many to One External Codes Value Mapping and Reverse View Extension

I do not see any reason why we are not allowed to map many external codes to one internal for AIF inbound port value mapping.

In fact, this is just a question of one additional table, which can be easily created as a copy of the exting one, and a slight change to three classes and AIF related forms.


For the demo's sake it is implemented for Customer and Units only, but you can add the same to any AX externally enabled table.

 Please download and use this extension to the standard AIF in AX 2012.

Another valuable feature of this project is the External codes Reverse View.


Any time I saw something like depicted, I dreamt to have a way to look into this halo in reverse.



The Reverse view enables you to find any existing relation between 1:1 and N:1 external and internal codes.

Filter by any column, export them to Excel, and go directly to the internal table by Edit or double-clicking.

Besides aforementioned, there are examples of using the powerfull AX objects, like:
- table map;
- Data Dictionary operations for scalability;
- set;
- InMemory and TempDB usage in Form and joins.