Search Suggest

June 2022

In the previous article i explained How to create a dialog in Dynamics 365 Finance and Operations. In this article "we learn what is a Container in Dynamics 365 Finance and Operations with a nice example". As we know in X++, data types are divided into primitive data types and composite data types. Examples for primitive data types are int, str, real …. etc and examples for composite data types Arrays, Containers, Collection Classes.

What is a container in X++ ?

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 coloumn created through AOT especially used to store images/files as a blob.

Why We Use containers in X++ ?

Primitive dataType variable can hold only one value and that too of same dataType, also it doesn’t support variables of different dataTypes. To overcome this problem X++ provides composite dataTypes arrays and containers, however arrays solve the former but supports only one dataType.

Container in Dynamics 365 Finance and Operations

Container can solves this problem by storing many elements of different dataypes. However there are few limitations with Containers like “container cannot store objects” and they can be addressed by collection classes and temporary tables concepts. Containers are most frequently used in Dynamics 365 development so let us explore Containers and its features.

Since a  container is not a class therefore classes/objects cannot be passed/put into a container. Also A container is a “PASS BY VALUE” type not “pass by reference” type which means while passing container the copy of container with values is passed not the reference. Therefore, any variable declared as a container is automatically initialized to an empty container that contains no values.

What is conPeek()?

The conPeek() is used to retrieve a specific element from a container. 

Syntax: anytype conPeek(container container, int number). 

Here container is the container to return an element from and the number is 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.

How to do it...

If you are a beginner or new to dynamics 365 Finance & Operations, you can use Microsoft'f Free Virtual Machine. Learn How to Set Up a Free Virtual Machine for Dynamics 365 Development.

The below example code shows how to declare a container and how to add values to a container also the examle shows how to retreive 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 the conatiner name.

class RunnableClass1

{

   /// <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=["Rafeeque","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)));

       }

   }

}

After successful build of the project you will get an output as shown below, which lists the three containers values  on infolog.

What is Container in Dynamics 365 Finance and Operations

After successful build of the project you will get an output as shown below, which lists the three containers values  on infolog.

What is Container in Dynamics 365 Finance and Operations

How the code works ...

Here an "[] " bracket is used to assign the values to the container and values are comma separated. 

For example conatiner EmpId, which stores employee ids [1000,1001,1002,... etc] and container EmpName, which stores employee Names["Rafeeque","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 is 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. Similiar way data are retrieved from EmpName and Salary containers. You can copy paste above codes directly to your visual studio.

Happy coding with D365Snippets

Useful Tags
What are the composite data types available in X Plus Plus? 
What is X++ used for? How do you add value to a container? 
How do you declare an array in X++?
How to get value from container x++?
What is container in X++? 
What is conPeek?
How do you add value to a container?
What are the composite data types available in X Plus Plus?
What is a container in D365?
X++ container with examples

In Microsoft Dynamics 365 Finance and Operations, a Dialog is a simple form with a standardized layout, which is created by using the Dialog system class. Dialogs are commonly used for small user tasks, such as filling the input values for generating a report, and presenting only the most important fields to the user when creating a new record etc. Since dialogues are used for small tasks, which is not commonly used for making complex forms, It also should not open a secondary window that requires user interaction. All user interaction should be carried out within the dialog.

If you are a beginner or new to dynamics 365 Finance & Operations, you can use Microsoft'f Free Virtual Machine. Learn How to Set Up a Free Virtual Machine for Dynamics 365 Development.

In Microsoft Dynmaics 365 Finance and Operations, a dialog is normally created by using X++ codes without storing the actual layout in the application object tree(AOT).

How to create a dialog in Dynamics 365 Finance and Operations

In Microsoft Dynmaics 365 Finance and Operations, the easiest way to create a dialog is by using the application class named Dialog. Controls which are used under the dialog is created by using the application classes DialogField, DialogGroup, and DialogTabPage 

How to create a dialogs using RunBase framework in Dynamics 365 Finance and Operations?

In Microsoft Dynmaics 365 Finance and Operations, The easiest way to create dialogs is to use the RunBase framework. This is because the framework provides a set of predefined methods, which make the creation and handling of the dialog well-structured, as opposed to having all the code in a single place.

What is RunBase framework in Dynamics 365 Finance and Operations?

RunBase : To create a job or an Action class – a program that carries out processes, such as accepting parameters from the user and then updating records in the database – you use the RunBase framework.
The framework is implemented by the RunBase application class and supplies many features, which include the following:

· Query

· dialog , with persistence of the last values entered by the user

· Validate

The RunBase application framework runs or batches an operation.An operation is a unit of work, such as the posting of a sales order or calculation of a master schedule. The RunBase framework uses the Dialog framework to prompt a user for data input. It uses the SysLastValue framework to persist usage data and the Operation Progress framework to show operation progress.The RunBase class is a framework for classes that need a dialog for user interaction and that need the dialog values to be saved per user.

RunBaseBatch :  You can design your own batch job by extending the RunBaseBatch class. You can also write code to schedule the batch to run. The batch runs on the Application Object Server (AOS). RunBaseBatch is an extension of RunBase – it adds a support for batch processing.

How to do this...

Here we are going to demonstrate a simple example which is creating a dialog form which is extending RunBase Framework class. In the next articles we will demonstrate more complex examples for RunBase frameworK.

If you are a beginner or new to dynamics 365 Finance & Operations, you can use Microsoft'f Free Virtual Machine. Learn How to Set Up a Free Virtual Machine for Dynamics 365 Development.

You can follow the below steps to complete the practical example,

1.  Create a project , here i created a project D365DialogProject.

2. I used already existing model Fleet Management. you can create new model as        per your requirement.

3. Add a new Runnable class and rename it NewCustDialog. Then , add the                    following code snippets:

4. Is is important to extend RunBase Application Class because the RunBase                  framework uses the Dialog framework to prompt a user for data input.

class NewCustDialog extends RunBase

{

   DialogField fieldAccount;

   DialogFIeld fieldName;

   CustTable   custTable;

   CustAccount custAccount;

   CustName custName;

   public container pack()

   {

       return conNull();

   }

   public boolean unpack(container _packedClass)

   {

       return true;

   }


   Object Dialog()

   {

       Dialog dialog;

       dialog = super();

       // Set a title fordialog

       dialog.caption( 'Simple Dialog');

       // Add a new field to Dialog

       fieldAccount =dialog.addField

(extendedTypeStr(CustVendAC), 'Customer account' );

       return dialog;

   }

   public boolean getFromDialog()

   {

       // Retrieve values from Dialog

       custAccount =fieldAccount.value();   

       return super();

   }

   public void run()

   {   

//Set Dialog field value to find CustTable

   custTable = CustTable::find(custAccount);

   if (custTable)

   {

       // Shows retrieved information

       info( strFmt('%1 -- %2' ,

custTable.AccountNum, custTable.name()));

   }

   else

   {

       error( 'Customer Account not found!');

   }    

   }

   public static void main(Args _args)

   {

       NewCustDialog custDialog = new NewCustDialog();       

       if(custDialog.prompt())

       {

           custDialog.run();

       }

   }

}

5. In order to test the dialog, right-click on this class and set as startup project. 

6. Build your project. Now, run the project. The following form will appear in the internet browser:

How to create a dialog in Dynamics 365 Finance and Operations

Here i input  the customer account value as "DE-001", which is the customer account code for the customer "Contoso Europe"  this customer details i created earlier for testing our example.

How to create a dialog in Dynamics 365 Finance and Operations

After successful build a dialog will open , putting a customer account code and press ok button, On my example I will use it to show the customer account information on infolog.

How to create a dialog in Dynamics 365 Finance and Operations

How the code works...

Here create a new class NewCustDialog with the above code, its important ro extend RunBase because the RunBase framework uses the Dialog framework to prompt a user for data input. By extending it from RunBase, we utilize astandard approach to develop data manipulation functions in Dynamics 365 for Operations. The RunBase framework will define a common structure and automatically add additional controls, such as the OK and Cancel buttons, to the dialog.

Then, we declare class member variables, which will be used later. The DialogField type variables are actual user input fields. The rest of the variables are used to store the values returned from the user input.

Then, we declare class member variables, which will be used later. The DialogField type variables are actual user input fields. The rest of the variables are used to store the values returned from the user input.

Then Override the method Dialog(), this method will be used to give “form” to our Dialog:

Then  Override the method getFromDialog(), the code below will be used to retrieve the Dialog field values:

Then Override the method run(), use it to process whatever you want to. On my example I will use it to show the customer account information on infolog.

In order to make this class runnable, the main() static method has to be created. Here, wecreate a new CustCreate object and invoke the user dialog by calling the prompt() method. Once the user has finished entering customer details by clicking on OK, we call therun() method to process the data.

Execute your class, check results.