19 January, 2010

Hybrid Development: Using VST to overcome the Cyclic reference of projects constraint in VBA

When customizing GP with Modifier/VBA you may run into situations where you need to create cyclic references between .vba Projects.  In this example, I needed to allow the assignment a Contract Type to each Item in Item Maintenance to meet a Customer's requirement.  Contract Type Lookup is in the Field Service dictionary and Item Maintenance is in the Dynamics dictionary.

I first tried using VBA to 1) Open the Contract Lookup after clicking on a lookup push button I added to Item Maintenance and then 2) Update a new string field I added to capture and display the Contact Type assigned to each item in Item Maintenance.  To do this with VBA I had to open Contract Lookup from Item Maintenance in the Dynamics dictionary and then set the value in my custom string field on Item Maintenance on the Contract Type Lookup Select After User Changed Event.  To do this, I would have to set a reference from Dynamics to FieldService AND from FieldService to Dynamics.  You'll quickly discover that this is not permitted in VBA.

Before the introduction of VST you would have had to create your own lookup window.  A workable solution, but not optimal.  Now, with the VST for GP the solution is simple.  You can use the Dictionary Assembly Generator (Dag.exe) to create an application assembly for your modified forms.  This is required to access local fields added to windows in GP using Modifier.  Over at The Dynamics GP Blogster, Mariano does a good job describing how to do use the Dag.exe in one of his posts on hybrid development techniques.  Mariano explains:

Use the Dictionary Assembly Generator (DAG.EXE) tool provided with Visual Studio Tools to generate the Application.Dynamics.ModifiedForms.dll application assembly for the forms dictionary.  Since DAG.EXE is a command line utility, go to the command prompt then go to the Visual Studio Tools SDK folder (typically under Program Files\Microsoft Dynamics\GP10 VS Tools SDK) to execute it, as follows:

dag.exe 0 "C:\Program Files\Microsoft Dynamics\GP\Dynamics.set" /F /N:Dynamics

After adding a reference to the Application.Dynamics.ModifiedForms.dll that to your VST project, you are able to use VST to launch Contract Type Lookup from Item Maintenance and set the value in Item Maintenance on the Contract Type Lookup Select After User Changed Event without issue.  The GPAddin.vb code may look like this:

The end result is the native Field Service Contract Type Lookup window nicely bound to the Dynamics Item Maintenance Window:

Next, you would need to save the Contract Type associated with the Item Number to the database.  You could do that using either VST or VBA.  That's beyond the scope of what I was trying to communicate here but not a bad subject for a future post.  Let me know what you think.

1 comment:

Mariano Gomez said...

Excellent use of hybrid development techniques! Before it was cross-dictionary, now the name of the game is "hybrid". Makes life so much easier.

Thanks for the props!

Mariano Gomez, MVP