Tuesday, April 6, 2010

Use Dynamics GP Lookups Using VS Toolkit

While searching for performing such operation, I have created a small sample that worked perfectly!!

This method uses Form.Open method to load lookup form and AddHandlers to handle the selection events, below steps I used to fulfill this request, in the example below, I am developing a customer and vendor statements for one of my clients:

1. Create the form that will load the lookup, the form will look like the below:


2. Add the needed form to the Customer Maintenance form as a menu:


This could be done by adding the following lines of code in the AddIns file under “Sub Initialize()”:

'Customer Statement
Dim CustomerStatementMenu As New System.EventHandler(AddressOf CustomerStatement_Menu)
Dynamics.Forms.RmCustomerMaintenance.AddMenuHandler(CustomerStatementMenu, "Customer Statement")

3. We need add handler to the “Select Button” on the customer lookup form just below the above lines:

'Customer Lookup
AddHandler Dynamics.Forms.CustomerLookup.CustomerLookup.SelectButton.ClickBeforeOriginal, AddressOf CustomerLookup_Handler

4. Handling the menu item for customer will call Customer Statement Menu sub as the below, make sure to define the customer statement form public to get the access later on:

Dim CustomerStatementForm As New CustomerStatement

Private Sub CustomerStatement_Menu(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub

5. Now we will need to handle the Select button event to get the selected customer, we’ll need to add two global variables, one as a Boolean to make sure that the lookup called by our application called “CalledByApplication” and the other to specify from where the lookup called and where to return the result –From or To-:

Private Sub CustomerLookup_Handler(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
     If CalledByApplication Then
         If CalledBy = "From" Then
             CustomerStatementForm.CustomerFrom.Text = Dynamics.Forms.CustomerLookup.CustomerLookup.CustomerNumber.Value
         ElseIf CalledBy = "To" Then
             CustomerStatementForm.CustomerTo.Text = Dynamics.Forms.CustomerLookup.CustomerLookup.CustomerNumber.Value
         End If

         CalledByApplication = False
         CalledBy = ""
     End If
End Sub

6. Now in our form at the lookup button event, add the following lines of code:

CalledByApplication = True
CalledBy = "From"

Viola, your application will call the GP lookup! Hope that helps.

Mohammad R. Daoud - CTO
+962 - 79 - 999 65 85 

No comments:

Related Posts:

Related Posts with Thumbnails