I will no longer be posting to Dynamics GP Land, and all new posts will be at https://blog.steveendow.com
Thanks!
By Steve Endow
When you develop a Dynamics GP customization, you may want to automatically open Dynamics GP windows to add dramatic flair to your application.
I mean really, let's be honest, what's cooler than saying your customization lets the user "drill down" into Dynamics GP? (Is that still a buzzword? I may be behind the times)
Take the GP Transaction Search tool as an example. When a user searches for an AP transaction, I thought it would be handy if the user could right click on a row and view both vendor information and transaction information directly in Dynamics GP.
Just because I developed the PM Transaction Search window doesn't mean that I want to (or need to) develop a new window just to view vendor info or transaction info.
Why not just leverage Dynamics GP windows to view that information?
I want the user to be able to right click or double click on a row in the grid and view the details in an existing Dynamics GP window.
Here's a full video with a code review of opening GP windows from .NET using Visual Studio Tools:
Fortunately, adding this drill-down functionality to a VS Tools AddIn for Dynamic GP is relatively easy. For some windows.
For other windows, it requires a slightly more involved process.
And, unfortunately, for some windows, it may be very difficult or impossible.
Let's start with the easy method.
These samples are from the free and open source code for the GP Transaction Search project, available on GitHub. You are welcome to clone the project from Visual Studio and download all of the code.
Here is the method for opening the Vendor Inquiry window. Note that this window has a single lookup field--when you open it in GP, you choose a vendor ID, and the vendor's information is displayed.
The process of opening this window using .NET is similar.
private void OpenPMVendorInquiry(string vendorID)
{
Controller.Instance.Model.PMSearchFocus = true;
PmVendorInquiryForm pmVendorInquiryForm = Dynamics.Forms.PmVendorInquiry;
PmVendorInquiryForm.PmVendorInquiryWindow pmVendorInquiryWindow;
pmVendorInquiryWindow = pmVendorInquiryForm.PmVendorInquiry;
pmVendorInquiryWindow.Open();
pmVendorInquiryWindow.VendorId.Value = vendorID;
pmVendorInquiryWindow.VendorId.RunValidate();
}
Create an instance of the GP form, then get the window object based on the form, then Open the window, populate the Vendor ID value, then call RunValidate.
If you've done a few projects with VS Tools for Dynamics GP, this may be familiar.
But what about this "Zoom" window?
It's an 'inquiry' window, but notice that it does not have a lookup field like the Vendor Inquiry window. This makes the zoom window different.
If you try to populate the Voucher No and Document Type fields on this window using .NET, you'll get a whole lot of nothing. GP will not retrieve or display the data for the transaction.
Hmmm.
So how does one open and populate this window using .NET? I didn't know.
So, I figured I would look at how Dexterity does it.
First, you need to enable the ScriptDebugger option in your Dex.ini file by following these simple instructions. Once that is done, setup the PM Transaction Inquiry Vendor window with a vendor selected and an invoice selected.
With that setup, click on the Debug menu on the main GP window, and select the last option, Log Scripts:
You will be prompted to create a file. I just called it PMInquiry.txt and saved it to my desktop.
Now that the script logging is enabled, go back to the PM Trx Inquiry Vendor window, with your invoice record selected, and click on the blue Document Number link in the scrolling window. That opens the PM Transaction Entry Zoom window, just like we want.
Now click on the Debug menu in GP, and click on Log Scripts to stop the logging. Then open your new PMInquiry.txt script log file.
It took me a minute to review the script and figure out what is going on, but I eventually saw this line.
'OpenWindow of form PM_Transaction_Entry_Zoom', 1, "00000000000000374", 2, 1, 7814
That's the window I wanted to open, and the command "OpenWindow" was a nice clue.
Okay, so that's a Dex command that is opening the window, how does that help me with my .NET project?
After doing some digging, I found that VS Tools lets you call some Dexterity Procedures. And wouldn't you know it, in .NET, there is a form called PMTransactionEntryZoom, just like what we see in the Dex log.
And under that form, there is a Procedures option, and under that is an OpenWindow procedure.
Dynamics.Forms.PmTransactionEntryZoom.Procedures.OpenWindow.Invoke(pmTrx.DOCTYPE, pmTrx.CNTRLNUM, pmTrx.DCSTATUS, 1, 7814);
In order to call the OpenWindow procedure, we use the OpenWindow.Invoke() method, into which we pass in a few parameters.
The Dexterity script log gives us some clues about the parameters we need to pass in, and Visual Studio Intellisense helps as well.
So the parameters are:
- NDocType
- SVoucher
- NDocStatus
- NCyView
- NCallerId
The first three are straightforward, and we can supply those from the data in the PM Transaction Search grid. CyView is apparently a Currency View option--I don't know the possible options for that parameter, but since we see a value of 1 in our Dex script, I used that value. And then CallerId is apparently the calling window, so I also used 7814 for that parameter, just like the Dex script.
Once that single line of code is in place, right clicking or double clicking on a row will open the PM Transaction Entry Zoom window and populate the data.
But if you use the PM Transaction Inquiry Vendor window to open different transaction types (PM Invoice, PM Payment, and POP Invoice), you will notice that it opens different Zoom windows. To replicate that functionality, I have the PM Transaction Search window open the same windows.
So for payments, it opens the PmManualPaymentsZoom window.
Dynamics.Forms.PmManualPaymentsZoom.Procedures.OpenWindow.Invoke(pmTrx.CNTRLNUM, pmTrx.DCSTATUS, 1, 7814);
And then I tried to open the PopInquiryInvoiceEntry window.
But...
I couldn't.
I tried using OpenWindow.Invoke to open that window, but Intellisense told me that the PopInquiryInvoiceEntry window does not have an OpenWindow procedure.
Dynamics.Forms.PopInquiryInvoiceEntry.Procedures
It has procedures, but OpenWindow is not exposed to VS Tools.
And since it's a zoom window with no lookup fields, I can't use the simpler method to open and populate the window.
So, I was stuck. There are apparently some GP windows you just can't open using VS Tools.
In theory, it may be possible to use Continuum and pass-through SanScript to open the window, but I didn't have the patience or time to figure out Continuum, so at the moment, the PM Transaction Entry window does not support drill down to POP Invoices. It simply opens the transaction in a PM Invoice Zoom window instead.
So it is usually possible to open a GP window to add drill down functionality to your .NET application, but just be aware that you may encounter a window that can't be opened properly from .NET.
UPDATE: I have received feedback from a few people that explained to me that the PopInquiryInvoiceEntry has an OpenWindow function. Instead of accessing Procedures, just change that to Functions, and OpenWindow will appear for the POP window. Apparently this is due to inconsistencies with how the POP module was developed.
Dynamics.Forms.PopInquiryInvoiceEntry.Functions.OpenWindow.Invoke("RCT1107", 2, 3, 1);
I have tested this and it works great. It will be included in GP Transaction Search v3.0.
Steve Endow is a Microsoft MVP in
Los Angeles. He is the owner of Precipio Services, which provides
Dynamics GP integrations, customizations, and automation solutions.
Hi Steve. I enjoyed your post on opening Dynamics GP window from VSTools. Just to say that the problem with opening the PopInquiryInvoiceEntry window is because OpenWindow is a function on that window, not a procedure. So if you look in PopInquiryInvoiceEntry.Functions you will find OpenWindow. Hope that helps!
ReplyDeleteHi Alex,
ReplyDeleteThanks for the comment. A few other Dex folks have explained to me that the POP OpenWindow is available under Functions, so I have tested that and got it working.
Thanks for the reminder that I had noted that issue on this post. I've updated the post with the pointer to use Functions rather than Procedures.
Thanks!
Steve