Axapta Dialog Validation - Stack Overflow

Axapta Dialog Validation - Stack Overflow:

Here is an example in AX 2009 of how to build a simple dialog using the RunBase class. In it I create a class called DialogExample and derive from RunBase. To show the dialog you simply need to run the class, but typically this would be done by pointing a MenuItem at the class.

public class DialogExample extends RunBase {     DialogField dialogName;     Name name;      #DEFINE.CurrentVersion(1)     #LOCALMACRO.CurrentList         name     #ENDMACRO }  Object dialog() {     Dialog dialog = super();     ;      // 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.     dialogName = dialog.addFieldValue(TypeId(Name), name);      return dialog; }  boolean getFromDialog() {     ;      // Retrieve the current value from the dialog.     name = dialogName.value();      return true; }  boolean validate(Object _calledFrom = null) {     boolean isValid;      isValid = super(_calledFrom);       // Perform any validation nessecary.     if (name != 'abc')     {         isValid = checkFailed('Name is not equal to abc') && isValid;     }      return isValid; }  Name parmName() {     ;      return name; }  public container pack() {     return [#CurrentVersion,#CurrentList]; }  public boolean unpack(container _packedClass) {     int version = conpeek(_packedClass, 1);      switch (version)     {         case #CurrentVersion:             [version,#CurrentList] = _packedClass;             break;         default :             return false;     }      return true; }  public static void main(Args args) {     DialogExample DialogExample;     ;      dialogExample = new dialogExample();      // Display the dialog. This only returns true if the the user clicks "Ok"      // and validation passes.     if (dialogExample.prompt())     {         // Perform any logic that needs to be run.         info(dialogExample.parmName());     } }
Typically in this scenario logic that needs to be run would be put in a run method on the class and then called into from main if the Ok button is clicked. Since the run method would be an instance method this gets rid of the need for the parm methods to access the value of the field on the dialog.

No comments:

Post a Comment