The everyday life of a Dynamics AX developer
I will demonstrate how to override methods on the dialog (in this case modified()), and how to read and set properties of controls.
For the sake of this demo, we will add a checkbox to the dialog that will allow us to set the enabled property of the date control.
It should look like this:
We will need to modify the data contract so a checkbox is displayed on the dialog that we can use to enable or disable the date control.
Add this variable to the class declaration of the KlForCustTesterDataContract class:
Then add this method to that same data contract
There’s nothing new here, we already did all of this in part 1
We will extend the SysOperationAutomaticUIBuilder class so we can override methods and properties of controls on our dialog.
First, create a new class, KlForCustTesterUIBuilder:
Things we will need in this class are:
So we add these variables to the class declaration:
We will first write the method that will override the modified of the checkbox control. Simply add a new method to the KlForCustTesterUIBuilder class:
The code above sets the enabled method on the dialogFieldTransDate object based on the value property of dialogFieldAllowModifyDate object, or alternatively, the _checkBoxControl variable.
As you may remember, we declared the DialogField variables in the class declaration. Of course we will still have to initialize these variables , and that’s what we’ll do when overriding the postBuild method.
Next, we need to override the postBuild method on our KlForCustTesterUIBuilder class. This method will be called after the dialog is created, so it is a good place to put our logic.
Override the method:
Next, let’s add some code to this method, starting with the code that retrieves the data contract object, which is pretty easy:
Next, we retrieve the DialogField objects:
In the code above, the bindInfo() method returns an object of type SysOperationUIBindInfo. This contains information about which dialog controls the data members are bound to. By providing a reference to the parmTransDate and parmAllowModifyDate member when calling the getDialogField() method, we get the dialog control that is associated with each member.
Next, we will register the method we want to override:
As you can see, we can use the registerOverrideMethod() method to override methods on dialog. This is a huge improvement over overriding methods on dialogs in 2009. We simply point to the method we want to override (FormCheckBoxControl.modified) and the method the needs to be executed (KlForCustTesterUIBuilder.allowModifyDateModified).
Finally, we initialize the value of the enabled property, and the complete method will look like this:
Now, we’ve created the UIBuilder class, but we still have to link it to our data contract. That’s what the SysOperationContractProcessingAttribute attribute is for.
To link the UIBuilder class to the data contract, open the classDeclaration method of the KlForCustTesterDataContract class, and add the SysOperationContractProcessingAttribute:
But wait (you already know what I’m going to say right), first click the Generate Incremental CIL button to generate CIL.
Right click the KlForCustTesterServiceController menu item we created on day 2, and choose open. You should see this dialog:
When you check the checkbox, you should see that the date field is enabled.
That concludes my blog posts about SysOperation, I hope you like it, and I’m looking forward to your feedback.
Have fun making batches!