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