Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamics AX 2012 Only One Copy of a Form Open

Anyone have any tips/code snippets for preventing more than one copy of a custom X++ form from being opened at a time?

Best case: Attempt to open another copy of the form, and the original gains focus

Acceptable: User receives a notice that the form is already open

like image 966
Brad Avatar asked Oct 17 '13 06:10

Brad


1 Answers

you could insert the code below into the form's init method. If you have any questions to the code don't hesitate to ask!

public void init()
{
    #define.CACHE_OWNER        ('MyForm')
    #define.CACHE_KEY_INSTANCE ('Instance')

    FormRun existingForm()
    {
        ;

        if (infolog.globalCache().isSet(#CACHE_OWNER, #CACHE_KEY_INSTANCE))
        {
            return infolog.globalCache().get(
                #CACHE_OWNER, #CACHE_KEY_INSTANCE);
        }
        return null;
    }

    void registerThisForm()
    {
        ;

        infolog.globalCache().set(#CACHE_OWNER, #CACHE_KEY_INSTANCE, this);
    }

    boolean isAlreadyOpened()
    {
        ;

        return existingForm() ? !existingForm().closed() : false;
    }

    void activateExistingForm()
    {
        ;

        existingForm().activate(true);
    }
    ;

    super();
    if (isAlreadyOpened())
    {
        activateExistingForm();
        this.close();
    }
    else
    {
        registerThisForm();
    }
}
like image 126
DAXaholic Avatar answered Oct 01 '22 23:10

DAXaholic