Unleashing Dynamics 365 Excellence: Your Source for Pro Tips and Snippets at D365Snippets.com

Our blog provides a curated collection of tips, tricks, and code snippets that streamline your workflow and enhance your proficiency.
Unleashing Dynamics 365 Excellence: Your Source for Pro Tips and Snippets at D365Snippets.com

How to create a dialog in Dynamics 365 Finance and Operations.

0

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.

Post a Comment

0Comments
Post a Comment (0)