Why Containers?
Composite dataTypes - Arrays, Containers, Collection Classes
Temporary Tables
For instance,
- Primitive dataType variable can hold only 1 value and that too of same dataType, if you want to store 500 values then you have to create/declare 500 variables and intialize them, also it doesn't support variables of different dataTypes. To overcome this problem AX provides composite dataTypes arrays and containers, however arrays solve the former but supports only one dataType.
- Container solves this problem by storing many elements of different dataypes. However there are few limitations with Containers like "container cannot store objects" and "performance implications" and they can be addressed by collection classes and temporary tables concepts. Containers are most frequently used in AX development so let us explore Containers and its features
Features of Containers:
Container Functions:
Below are some of the most common container functions with examples.conPeek() Function
The conPeek() is used to retrieve a specific element from a container.
Syntax: anytype conPeek(container container, int number)container - The container to return an element from.
number - The position of the element to return. Specify 1 to get the first element.
Return value: The element in the container at the position specified by the number parameter. The conPeek function automatically converts the peeked item into the expected return type.
Syntax: anytype conPeek(container container, int number)container - The container to return an element from.
number - The position of the element to return. Specify 1 to get the first element.
Return value: The element in the container at the position specified by the number parameter. The conPeek function automatically converts the peeked item into the expected return type.
void daxErp_conPeek()
{
// container declaration and initialization with 2 values
container daxConBeta = ["Welcome", 8594];
str charHolder;
;
// conPeek() function returns the value being held in a specific position in the container.
// (Note: It returns anyType)
// Here printing 1st and 2nd values from daxConBeta to info
charHolder = conPeek(daxConBeta, 1);
info(strFmt("Container daxConBeta conPeek() values are :-
%1, %2", charHolder, conPeek(daxConBeta, 2)));
}
http://imdaxershiv.blogspot.com/2016/03/dynamics-ax-tutorial-x-containers.html
http://daxingwitheshant.blogspot.com/2018/07/collection-classes.html