Pages

Tuesday, November 15, 2011

How to call a form from code and make it modal

This is how to open a form from X++ and set it modal.  Modal means it is on top of the other windows and you can not click on the ones behind it.  I have this just in a clicked event on a button.


void clicked()
{
    CustTable   custTable;
    FormRun     formRun;
    Args args = new Args();
    ;
    
    // Just selecting a random record in CustTable
    select firstonly custTable;

    // This is the name of the form you are opening
    args.name(formstr(CustTable));
    
    // This is the optional record you are passing it
    args.record(custTable);

    // This builds the formrun
    formRun = ClassFactory.formRunClass(args);
    formRun.init();
    formRun.run();

    // This waits until the form closes
    if (!formRun.closed())
        formrun.wait(true);
}

3 comments:

  1. Even better you can call the wait method from the form itself!

    public void run()
    {
    super();
    element.wait(true);
    }

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. This is my first time i visit here and I found so many interesting stuff in your blog especially it's discussion, thank you. www.wirelessinnovationalliance.com

    ReplyDelete