Container Data Type Example in Dynamics 365 Finance and Operations

0

Container Data Type Example in Dynamics 365 Finance and Operations

A container is a “composite data type”, which contains an ordered sequence of values (primitive dataTypes – int, str, real, date, boolean, enum, etc.) or other containers or/and some composite data types. A container can be stored in the database as a database column created through AOT especially used to store images/files as a blob.

The below example code shows how to declare a container and how to add values to a container also the example shows how to retrieve the data from a container, Here we have declared three containers "EmpId" "EmpName" and "Salary",  where "EmpId" stores employee ids, "EmpName" stores the name of the employees and "Salary" stores employee salary. For declaring a container we use the keyword "Container" the container name.

...

class ContainerExample
{
   /// <summary>
   /// Runs the class with the specified arguments.
   /// </summary>
   /// <param name ="_args">The specified arguments.</param>
   public static void main(Args _args)
   {
       container EmpId;
       container EmpName;
       container Salary ;
       int i;
       EmpId=[1000,1001,1002,1003];
       EmpName=["James","John","Peter","Dev"];
       Salary=[50000.00,45000.00,75000.00,40000.00];
       for(i=1;i<=4;i++)
       {
           info(strFmt("EmpId
= %1 -- EmpName = %2 -- Salary  = %3",conPeek(EmpId,i),conPeek(EmpName,i),conPeek(Salary,i)));
       }
   }

...

Here an "[] " bracket is used to assign the values to the container and values are comma separated. 
For example, container EmpId, which stores employee ids [1000,1001,1002,... etc], and container EmpName, which stores employee Names["James", "John",...etc]. this is the way a container stores data.

Then how to retrieve data from containers?. The conPeek() is used to retrieve a specific element from a container. 

From the above example, it is very clear that values from container EmpId are retrieved by using the code conPeek(EmpId, i), where EmpId is the name of the container and "i" is used for the position of the element to be returned. Similarly, way data are retrieved from EmpName and Salary containers. You can copy and paste the above codes directly to your visual studio.

Post a Comment

0 Comments
Post a Comment
>
To Top