In the blog post series by David Musgrave, he shows how to customise the GP company login boxes, to make them long enough to see very long company names in full. David uses Dexterity in the third part of the series. However in the latest he attempts to do the same using an addin, albeit he “cheats” by passing in the SanScript. Note this is not a supported method.
By using the Continuum COM library to allow .NET code in the Dynamics GP Visual Studio addin to pass SanScript through to the GP we CAN do it, see how I did it!
The original article can be found here:
So David had a problem getting it working, I had Visual Studio open on my Addin project, so I gave it a go.
Make a reference to the Continuum
This is a COM object in, so go to your project reference and search for “contin” and then add the reference. Ensure you marry the version number with the version of GP you are using.
Store the script in a project resource
Under the project settings, you can store resources. This is a good place to put your scripts as it deals with line feeds and keeps them in an intact form for future editing.
Go to the resources tab of the project properties, create a new resource and paste in the script provided by David. We are going to use the .NET code to run the script, so we don’t need to put it in a procedure, only take the fragment that does the deed. Name the resource LoginResizeScript
Add event handler
Now when the company login window is opened we want to execute the script to resize the text boxes on that window. So to me it seems like a good plan to add and event handler to the company switch form. Now go to your GPAddin.vb and add and event handler like this for the company switch form.
Sub Initialize() Implements IDexterityAddIn.Initialize
'You should add code to only execute once in lifetime
AddHandler Microsoft.Dexterity.Applications.DynamicsDictionary.OpenSwitchCompanyFormProcedure._Instance.InvokeAfterOriginal, AddressOf DoLoginResize
Deal with the namespaces
Important as the project reference messes you up!
Imports DynamicsGP = Microsoft.Dexterity.Applications.Dynamics
Execute the script
So next the script needs to run in response to the event firing on the Switch Company event handler. Add the following to your GPAddin.vb .
The SanScript is now held in a project resource we can reference by My.Resources.Resources.LoginResizeScript so we push this into the ExecuteSanscript method.
Public Sub DoLoginResize(sender As Object, e As EventArgs)
Dim CompilerApp As New Dynamics.Application
Dim CompilerMessage As String = Nothing
Dim CompilerError As Integer
' Execute SanScript in Dynamics GP
CompilerError = CompilerApp.ExecuteSanscript(My.Resources.Resources.LoginResizeScript, CompilerMessage)
If CompilerError <> 0 Then
Resulting resized controls – it works!
And hey it works from VB.NET too! I love Visual Studio and Dynamics GP!