Handling Modal Dialogs in Microsoft Dynamics GP

In the few years that I have spent on customizing Microsoft Dynamics GP, I have often come across the challenge, which I am sure everyone has come across. The challenge has been in triggering a pop up message which shows up in GP, and manipulating the events on the pop up window.

There are many types of pop up windows in GP, which are called in many ways like using the following commands:

  • warning command
  • error command
  • ask() command
  • error messages displayed using the Warning_Dialog procedure.

It has always been a challenge in tracking this window, until I had found out a way to do the same, and I felt this would be a great article to share to the entire developer community, especially who are yet to find a solution for the same. :-)

This is possible using VBA, where for every window, there is an event in VBA like

Private Sub Window_BeforeModalDialog(ByVal DlgType As DialogType, PromptString As String, Control1String As String, Control2String As String, Control3String As String, Answer As DialogCtrl)

This event is available for all windows which are added to VBA.  This event will trigger whenever a modal dialog window is opened from the window which has been added to VBA.

E.g.: Assuming the case on a particular window, when the user clicks on the Delete button, a pop up window with the message string “Do you want to delete this record?” pops up, with the choices like Yes and No.

When this pop up is fired, the VBA event fires and the logic we write into this event can manipulate the way the modal dialog should behave. Let us assume that the user always needs to click on the Yes button. In Dexterity, this window cannot be triggered. So we choose this event in VBA, where we can achieve the result.

Once the above mentioned event is fired, the PromptString variable, will hold the value of the message displayed on the modal dialog window. In our case, this will be “Do you want to delete this record?”. We can check for the message displayed on this modal dialog window and perform the necessary action. In this case the code will look something like given below.

Private Sub Window_BeforeModalDialog(ByVal DlgType As DialogType, PromptString As String, Control1String As String, Control2String As String, Control3String As String, Answer As DialogCtrl)

If PromptString = "Do you want to delete this record?" Then
       Answer = dcButton1
End If
End Sub

The value Answer will have the following options to choose from:

  • dcButton1
  • dcButton2
  • dcButton3
  • Yes
  • No
    The value for dcButton1, dcButton2 and dcButton3 indicate the values for 3 command buttons that may be available on the modal dialog window.
    When this event is fired, the modal dialog is opened logically and the Yes first button on the window, which is Yes in our case is fired and the business logic for the Yes button is fired automatically.
    This, for me, has been a very helpful piece of code logic, which I am sure will assist any developer who has been wondering how to handle such dialogs in GP. :-)
    Until next post, have a good week end… :-)
VN:F [1.9.13_1145]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.13_1145]
Rating: 0 (from 0 votes)

February 14, 2009 В· veeyeskay В· 2 Comments
Posted in: Customizations, Dynamics, Great Plains, System Total Views: 710