Wednesday, October 30, 2013

Custom box

hi all,

Don't know about you, but I've been using the Box class quite often. But sometimes I need a dialog with other options than the ones out-of-the-box Ax provides. Some situations just don't get covered by a Yes/No choice. That's where my CustomBox class kicks in: you get the look and feel of the standard Ax box, but with custom buttons.

It comes with only two public method, so it's pretty simple:
- a public static 'construct' method to create the object
- a public instance 'prompt' method to  ... well, to prompt the dialog.

The constructor takes 5 parameters:
- the message/question itself 
- a container holding the button labels: for each element in the container a button will be created using the provided label
- an integer indicating which of the elements of the container should be the default button. This one is optional, the first button is the default ... by default
- the title to be used. This one is optional, by default it states 'Microsoft Dynamics' on top of the dialog
- a boolean to make the dialog modal. This one is also optional but 'true' by default.

The prompt method doesn't take any parameters but does make sure to prompt the dialog and that the number of the button that was pressed is returned.

The example below should make the above more clear:

static void CustomBox_TryOut(Args _args)
    CustomBox       box;
    int             retValue;

    box = CustomBox::construct("Press one of my buttons",
                               ["I will", "I won't", "Not sure"], 

                               "Pick a button");
    info(strFmt("you pressed button %1", box.prompt()));


The dialog triggered by the prompt method would look like this:

And the result in the infolog:

Source code of the class and a tryout job bundled in a private project can be downloaded here.

As with the standard Ax Box class, this class is also running on the client. So make sure it's not included in any server side batch or CIL code.


1 comment:

  1. Wow! This is a very useful blog and I really help us so much. Thank you for sharing valuable information.
    custom boxes