Dynamics AX 2012 only one copy of the form is open

Does anyone have hints / code snippets to prevent more than one copy of the X ++ user form from being opened at the same time?

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

Valid: the user receives a notification that the form is already open

+6
source share
2 answers

you can paste the code below into the init form. If you have any questions about the code, feel free 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(); } } 
+10
source

Add the following code to the form's init method as follows. No other changes are required.

 public void init() { #define.CACHE_OWNER('MyForm') int hWnd; super(); if (infolog.globalCache().isSet(#CACHE_OWNER, curUserId())) { hWnd = infolog.globalCache().get(#CACHE_OWNER, curUserId()); } if (WinApi::isWindow(hWnd)) { element.closeCancel(); WinAPI::bringWindowToTop(hWnd); } else { infolog.globalCache().set(#CACHE_OWNER, curUserId(), element.hWnd()); } } 
0
source

Source: https://habr.com/ru/post/956140/


All Articles