Sunday, July 8, 2018

How to Hide or disable ‘Cancel button’ on dialog In AX


Just leaving a quick tip. Sometimes for whatever reason we might need to hide the Cancel button or just disable it depending on a certain condition.
The following piece of code shows only the part where you should overwrite the method, if you need instruction about how to create a dialog please check my post How to: Create a simple Dialog through X++.

Overwrite method Dialog():


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Object dialog()
{
    FormBuildCommandButtonControl   cancelButton;
    ;
    dialog = super();
    //Add dialog fields
    cancelButton = dialog.formBuildDesign().control( 'CancelButton');
    //Disable the Cancel button
    cancelButton.enabled( false);
    //Hide the Cancel button
    cancelButton.visible( false);
    return dialog;
}

That’s it, there is no other complication. You can use these commands anywhere on the Class if you need to hide or disable because of a condition.

No comments:

Post a Comment