#GPPT Controlling System Dialogs using Modal Dialog Focus Triggers

David Meego - Click for blog homepagePreviously, we have discussed controlling the Report Destination Dialogs and even External Dialogs using GP Power Tools but have not published any examples of controlling the standard System Dialogs shown when the warning, error, ask() or debug commands are used in Dexterity.

This example shows how GP Power Tools adds this functionality not normally available for use with Dexterity. Visual Basic for Applications and Visual Studio Tools both have the ability to trigger before and after Modal Dialogs, but Dexterity does not. GP Power Tools adds the functionality with its Modal Dialog Focus Triggers.

To control a modal dialog with a GP Power Tools Trigger, you can use the Trigger Type: Focus Event and the Trigger Event: Modal Dialog.

If you want to change the wording on the dialog or automatically press a button on the dialog, use Trigger Attach: Before Original. If you just want to know that the dialog has been dismissed and/or what button was pressed use Trigger Attach: After Original.

The example in this article will automatically press “Save” when asked “Do you want to save changes?” on the Vendor Maintenance (PM_Vendor_Maintenance) window.

The script will contain all the parameters and the suggested options to use them. In this example, I am using getmsg(1000) instead of hardcoding the text. This makes it compatible with all languages. To identify the message number, I used the Resource Information window in Messages & Warning mode. Setting the value of OUT_Answer allows the dialog to be dismissed before it is even displayed.

You can also change the values of IN_Prompt and IN_Control1, IN_Control2, & IN_Control3 to change the text displayed on the dialog. This is not recommended as it can break other code that is triggering on the same dialog.

Note: You can also use the MBS_getmsg Helper Function if the message is in a different dictionary, or use the Messages Setup window to store the text for each language and MBS_Get_Message Helper Function to retrieve the value for the current Language ID.

WARNING: Do not use any Dexterity commands that can open a system dialog in the trigger script as this can cause an infinite loop and crash Dynamics GP. If you need to display a warning after dismissing the dialog, use the actions tab and use OUT_Condition =  true;

The project is just the single example trigger described above.

Downloading and Installing

Download the example code, import using the Project Setup window (now possible for first time imports with Build 28.8 onwards), or use Configuration Export/Import window (for older builds):

This code will be not active on next login or after switching companies (as it is not marked to automatically start), you can use start the triggers manually from the Project Setup window.

More Information

If the modal dialog that opens is actually a modal Dexterity form, this method will not work. However, you can use the same methods as used for controlling the Report Destination windows in the article below:

Sometimes it is not possible to identify a window that a system dialog is related to and so you cannot capture the event and use the methods in this article. If this situation occurs and you cannot use other methods to prevent the dialog opening in the first place, then you can try the method in the article below:

For more information see:

I hope this information is helpful.

David

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

2 thoughts on “#GPPT Controlling System Dialogs using Modal Dialog Focus Triggers

Leave a Reply