Code highlighting

Thursday, July 01, 2010

Tutorial: Brief description of ways to close a form in AX

We had this question asked on one of the internal AX forums, and Michael Fruergaard wrote a short description of each method you can use.

Re-posting it here with some extra comments, so that new developers can read and understand, when to use what method.

There are “only” 5 ways to close a form:
  • Close - close the form. Similar to the 'X' button.
  • CloseOK – close the form, and set the OK flag – called by the Commandbutton::Ok
  • CloseCancel – close the form, and set the Cancel flag – called by the Commandbutton::Cancel
  • CloseSelectRecord – close the lookup form, and set return record
  • CloseSelect – close the lookup form, and set return value

The below methods (note their names are in past-tense) are used to determine if or how a form was closed:
  • Closed – Returns true, if the form is no longer open
  • ClosedOK – Return true, if the form was closed by the user clicking ‘OK’
  • ClosedCancel – Returns true, if the form was closed by the user clicking ‘Cancel’

Finally, CanClose() is called inside super() of any of the close methods. If CanClose() returns false, the form is not allowed to close.

5 comments:

  1. Hi,

    What about infolog.close() method?

    Regards,
    Alex
    ---------
    Microsoft Dynamics AX Add-on for developers(Improved IntellySense,
    additional hotkeys etc) - http://www.axassist.com

    ReplyDelete
  2. Infolog.close() is a special method, called from the kernel (through infolog.formNotify()), when super() is called inside the close() method.

    It does not actually do anything visible, simply updates some global variables for lastActiveForm and document handling.

    Or were you asking something else?

    ReplyDelete
  3. CanClose is certainly called AFTER closeOk or closeCancel. I have not tried any of the other routines..

    ReplyDelete
  4. Well, not really. If I am to be very precise, canClose is called inside closeOK and other close* methods.

    What I meant by saing it's executed before is that canClose result will influence how the close methods behave.

    The call stack would be like this:
    closeOK before super
    canClose before super
    canClose after super
    closeOK after super

    ReplyDelete
  5. hai when i am using element.close(); ,the form is closing and showing the same form which is empty.. can anyone help me ...

    ReplyDelete

Please don't forget to leave your contact details if you expect a reply from me. Thank you