06 Sample GPAddin.vb code

The first line of code is the hardest. Where to start?

Our mission here is RAD. Rapid Development. To that end, without much discussion, you'll find below the first code that you'll need to write a VSTools modification. The sample code is on the PM Vendor Maintenance window, but any window will do.

This is the code for the GPAddins.vb class

Imports Microsoft.VisualBasic
Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports Microsoft.Dexterity.Bridge
Imports Microsoft.Dexterity.Applications
 
Public Class GPAddIn
    Implements IDexterityAddIn
    'declare a class for the PMVendorMaintenance form. The class is below
    Dim oPMVendorMaintenance As New PMVendorMaintenance
 
    Sub Initialize() Implements IDexterityAddIn.Initialize
        'this runs right after the Username/Password box appear when Dynamics launches
        Try
 
            'add a handler, when the Vendor ID changes our VendorIDChange code will run
            AddHandler Dynamics.Forms.PmVendorMaintenance.PmVendorMaintenance.VendorId.Change, AddressOf oPMVendorMaintenance.VendorIDChange
            AddHandler Dynamics.Forms.Toolbar.OpenAfterOriginal, AddressOf ToolbarOpen
 
        Catch ex As Exception
 
        End Try
    End Sub
 
End Class

 

This is the code for our PMVendorMaintenance class. All code for that window will go here. In our case we intend to populate a custom field here.

Public Class PMVendorMaintenance
    Sub VendorIDChange(sender As Object, e As EventArgs)
        Try
            'do something here
 
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, True)
        End Try
    End Sub
End Class

 

This piece of code handles changing the database when the user switches companies

Sub ToolbarOpen(sender As Object, e As System.EventArgs)
    Try
 
        App.Database = Dynamics.Globals.IntercompanyId.Value
 
        'get the server
        Dim backup As Microsoft.Dexterity.Applications.DynamicsDictionary.SyBackupRestoreForm
        backup = Microsoft.Dexterity.Applications.Dynamics.Forms.SyBackupRestore
        App.SQLServer = backup.Functions.GetServerNameWithInstance.Invoke
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
 
 
End Sub

 

 

 


RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences