Create dialog form using X++

Dynamics 365 gives the capability to create dialog form.We can however also create a dialog form through code dynamically at runtime.


  1. Create a class called DEMODialog extending RunBase

  2.  public class DEMODialog extends RunBase  
     {  
     }  
    

  3. Add global variables that will be the parameters that will be accepted in our dialog

  4.  public class DEMODialog extends RunBase  
     {  
       DialogField       dialogSalesId;  
       SalesId salesId;  
       FormDataSource     formDataSource;  
     }  
    



  5. Create dialog method to give the dialog caption, add the field, add field label. Look at the image at the last to understand the below code.

  6.  Object dialog()  
       {  
         Dialog dialog = super();  
         ;  
         dialog.caption("Dialog caption");  
         dialog.addTabPage("Tab page");  
         DialogGroup dialogGroup = dialog.addGroup("dialog group");  
         // Add a field for a name to the dialog. This will populate the field with  
         // any value that happens to be saved in name from previous uses of the  
         // dialog.  
         dialogSalesId = dialog.addField(extendedTypeStr(SalesId));  
         dialogSalesId.label("Salesid");  
         return dialog;  
       } 
    

  7. Override the validate method to validate if a value is provided in the field(if needed)

  8.  boolean validate (Object _calledFrom = null)  
       {  
         boolean isValid;  
         isValid = super(_calledFrom);  
         // Perform any validation nessecary.  
         if (!dialogSalesId.value())  
         {  
           isValid = checkFailed("Validation failed")) && isValid;  
         }  
         return isValid;  
       }  
    

  9. Create the main method to execute the dialog box.

  10.  public static void main (Args _args)  
       {  
         DEMODialog demoDialog= new DEMODialog();  
         // Display the dialog. This only returns true if the the user clicks "Ok" and validation passes.  
         if (demoDialog.prompt())  
         {  
            //Logic when Ok is clicked goes here  
         }  
    

  11. Create an action menu item with the object type as class and object as DEMODialog.
  12. Open the menu item to trigger the dialog.

The final dialog that opens up :

Final Dialog




Comments