I am working on a project that involves automating a process in Dynamics GP. Since there is no API for the particular steps I need to automate, I'm having to use the low-tech method of opening a GP window, populating some field values, and clicking a few buttons.
This is fairly easy to do with Visual Studio Tools for Dynamics GP...in concept.
But, unsurprisingly, Dynamics GP seems to always have to have the last word, and such seemingly simple projects are rarely easy.
In my particular case, after I performed the last button click on the GP window, Report Destination windows would appear to print posting reports.
The process I am automating generates not one, or two, or four, but FIVE report destination windows. Yes, it is possible to turn off the reports so that the window doesn't appear, but that change would affect many other processes throughout GP where the client might want to actually print some of the posting reports. It is possible to temporarily update the posting report settings in SQL to disable them, and then quickly re-enable them, but that method runs the risk of disabling at the same time that another user needs the report.
Unfortunately, the Report Destination dialog boxes are not standard modal dialogs that would be detected by the BeforeModalDialog event handler in VS Tools. So, some "off roading" is required.
When I ran into this problem I was lucky enough to find this excellent post by Paul Maxan on the Code Project web site.
Paul wrote a great article and did a very nice job crafting code that uses the Windows API to detect the Report Destination dialog box and use windows handles and messages to click through the dialogs.
He posted some very nice code that I packaged up into a separate class that can be easily invoked just about anywhere in your VS Tools project.
During my testing on GP 2013, I found that his combination of TAB + ESC didn't work for some reason. After some fiddling, I found that ESC by itself did work, so I have used that in my GP 2013 project.
The Report Destination dialog boxes still flash on screen as they are dispatched by Paul's "Closer" code, but it seems to work well and definitely gets the job done.