#GPPT Hiding Windows During Automations

David Meego - Click for blog homepageUsing the GP Power Tools – Developer Tools module for customization is a great method of automating processes in Microsoft Dynamics GP as well as customizing behavior to meet the requirements of your business.

Many customers are also using GP Power Tools to replace Visual Basic for Applications now that it is “End of Life” and unsupported.

I was recently asked how to hide a window opened and closed as part of an automation using GP Power Tools. This article explains the techniques you can use to open a window as hidden.

The trick is to use the Trigger Setup window to create a Trigger with the Trigger Type: Focus Event, Trigger Event: Window Pre, Trigger Attach: Before Original. After entering the Form and Window on the Resource Tab, select the Open Window Hidden checkbox on the Actions tab. In the Script tab make sure OUT_Condition in the Script is set to true for the window to be opened as hidden.

In Microsoft Dynamics GP it is actually not possible to open a window hidden. The method used to open a window “hidden” is to open it outside of the visible area of the desktop. When GP Power Tools opens a window as hidden, it internally temporarily disables the Window Position Check feature to stop it moving the window back to the visible desktop.

Note: Once the window has been opened, you must ensure that the window is closed once your automation code has completed. Use the run script command on the Close Button, Save Button, OK Button if it exists to close the window, or as a last resort use the close window command. If you don’t close the window, the user will not be able to see it unless they restart GP or use the mouse and keyboard trick to get the window back: Where has my Microsoft Dynamics GP window gone?

However, this trigger will run every time the window is opened. You will need a way to differentiate between when the window is opened by the user and when the window is opened as part of your automation process. Below are four ways you can handle this, with the last method being the preferred approach.

  1. Write the trigger, but do not start it automatically. Use the MBS_Trigger_Start and MBS Trigger_Stop Helper Functions in your automation scripts to register the trigger before you open the window and unregister it afterwards. Note: This method has the issue that every time you register the trigger it is assigned an integer trigger tag value. If this method is used over and over again, you will eventually use up all 32767 available values. So, this is not good for automated repetitive tasks such as importing data. 
  2. Write the trigger, but do not start it automatically, also select the Stop Trigger after met checkbox on the Options tab. Use the MBS_Trigger_Start Helper Function in your automation scripts to register the trigger before you open the window. The trigger will unregister after it has executed. Note: This method still has the issue that every time you start the trigger, it is assigned a new trigger tag integer value.
  3. Write the trigger and start it automatically. Use a Boolean Memory Parameter and the MBS_Memory_Get_Boolean Helper Function to read it and only set OUT_Condition to true when the value read (usually MBS_Memory_Boolean) is true. In the script before you open the window use the MBS_Memory_Set_Boolean Helper Function to set the Memory Parameter to true and set it back to false after the window is opened. Note: This method does need you to remember to use MBS_Memory_Del_Boolean Helper Function to delete the Memory Parameter when you have finished using it. 
  4. Write the trigger and start it automatically, but temporarily disable the trigger until it is needed. Use the Start Trigger Temporarily Disabled checkbox on the Options tab. To automatically disable the trigger after the window has opened, also set the Temporarily Disable Trigger after: Trigger Executed. In the script before you open the window use the MBS_Trigger_EnableSingle Helper Function to enable the trigger. No action is needed after the window is opened as the trigger will automatically disable itself again. Note: This method of Enabling and Disabling the trigger is better than Starting and Stopping the trigger as the trigger is only started once and only use the one trigger tag integer.

Hopefully these techniques will provide the control you need to hide a window during automation processes.

Note: These techniques cannot be used to hide a modal window which will not allow the window to be moved. Control modal dialogs can be achieved with the Focus Trigger on the Modal Dialog Event.

Enjoy

David

This article was originally posted on http://www.winthropdc.com/blog.

One thought on “#GPPT Hiding Windows During Automations

Leave a Reply