I've written some c# code to look up customers by name because out customer id's are all 8 digit numeric numbers now.
I added custom lookup buttons to some of the forms...My problem is I only get back the customer number and the customer name and the rest never populates.
Any idea why? I'll post my code here.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Dexterity.Bridge;
using Microsoft.Dexterity.Applications;
using Microsoft.Dexterity.Applications.DynamicsDictionary;
using System.Windows.Forms;
namespace DynamicsGPAddin
{
public class GPAddIn : IDexterityAddIn
{
// IDexterityAddIn interface
//RmCustomerInquiryForm rmCustomerInquiryForm = Dynamics.Forms.RmCustomerInquiry;
public static Boolean ReturnToLookup = false;
public void Initialize()
{
//this.rmCustomerInquiryForm.OpenAfterOriginal = RmCustomerInquiryForm_OpenAfterOriginal;
DynamicsGpModified.Forms.SopEntry.SopEntry.CustomerName.LeaveAfterOriginal = SOPEntry_CustomerName_LeaveAfterOriginal;
DynamicsGpModified.Forms.SopEntry.SopEntry.LocalLookupButtonCn.ClickAfterOriginal = SOPEntry_LocalLookupButtonCn_ClickAfterOriginal;
DynamicsGpModified.Forms.RmSalesEntry.RmSalesEntry.CustomerName.LeaveAfterOriginal = RMSalesEntry_CustomerName_LeaveAfterOriginal;
DynamicsGpModified.Forms.RmSalesEntry.RmSalesEntry.LocalPushButtonM147.ClickAfterOriginal = RmSalesEntry_LocalPushButtonM147_ClickAfterOriginal;
DynamicsGpModified.Forms.RmCashReceipts.RmCashReceipts.CustomerName.LeaveAfterOriginal = RMCashReceipts_CustomerName_LeaveAfterOriginal;
DynamicsGpModified.Forms.RmCashReceipts.RmCashReceipts.LocalPushButtonM83.ClickAfterOriginal = RmCashReceipts_LocalPushButtonM83_ClickAfterOriginal;
DynamicsGpModified.Forms.RmTransactionInquiry.RmTransactionInquiry.CustomerName.LeaveAfterOriginal = RMTransactionInquiry_CustomerName_LeaveAfterOriginal;
DynamicsGpModified.Forms.RmTransactionInquiry.RmTransactionInquiry.LocalPushButtonM18.ClickAfterOriginal = RMTransactionInquiry_LocalPushButtonM18_ClickAfterOriginal;
DynamicsGpModified.Forms.RmCustomerMaintenance.RmCustomerMaintenance.CustomerName.LeaveAfterOriginal = RMCustomerMaintenance_CustomerName_LeaveAfterOriginal;
DynamicsGpModified.Forms.RmCustomerMaintenance.RmCustomerMaintenance.LocalPushButtonM109.ClickAfterOriginal = RMCustomerMaintenance_LocalPushButtonM109_ClickAfterOriginal;
Microsoft.Dexterity.Applications.SmartListDictionary.CustomerLookupForm custlookupform = SmartList.Forms.CustomerLookup;
custlookupform.CustomerLookup.SelectButton.ClickBeforeOriginal = new System.ComponentModel.CancelEventHandler(custSelectButton_ClickBeforeOriginal);
}
private void SOPEntry_CustomerName_LeaveAfterOriginal(object sender, EventArgs e)
{
//MessageBox.Show(DynamicsGpModified.Forms.SopEntry.SopEntry.CustomerName.Value);
dynamic gpWindow = DynamicsGpModified.Forms.SopEntry.SopEntry;
FindFirstCustByName(gpWindow);
}
private void SOPEntry_LocalLookupButtonCn_ClickAfterOriginal(object sender, EventArgs e)
{
dynamic gpWindow = DynamicsGpModified.Forms.SopEntry.SopEntry;
LaunchCustomerLookup(gpWindow);
}
private void RMCustomerMaintenance_LocalPushButtonM109_ClickAfterOriginal(object sender, EventArgs e)
{
dynamic gpWindow = DynamicsGpModified.Forms.RmCustomerMaintenance.RmCustomerMaintenance;
LaunchCustomerLookup(gpWindow);
}
private void RMCustomerMaintenance_CustomerName_LeaveAfterOriginal(object sender, EventArgs e)
{
//dynamic gpWindow = DynamicsGpModified.Forms.RmCustomerMaintenance.RmCustomerMaintenance;
//FindFirstCustByName(gpWindow);
}
private void RMTransactionInquiry_LocalPushButtonM18_ClickAfterOriginal(object sender, EventArgs e)
{
dynamic gpWindow = DynamicsGpModified.Forms.RmTransactionInquiry.RmTransactionInquiry;
LaunchCustomerLookup(gpWindow);
}
private void RMTransactionInquiry_CustomerName_LeaveAfterOriginal(object sender, EventArgs e)
{
dynamic gpWindow = DynamicsGpModified.Forms.RmTransactionInquiry.RmTransactionInquiry;
FindFirstCustByName(gpWindow);
}
private void RmCashReceipts_LocalPushButtonM83_ClickAfterOriginal(object sender, EventArgs e)
{
dynamic gpWindow = DynamicsGpModified.Forms.RmCashReceipts.RmCashReceipts;
LaunchCustomerLookup(gpWindow);
}
private void RMCashReceipts_CustomerName_LeaveAfterOriginal(object sender, EventArgs e)
{
dynamic gpWindow = DynamicsGpModified.Forms.RmCashReceipts.RmCashReceipts;
FindFirstCustByName(gpWindow);
}
private void RMSalesEntry_CustomerName_LeaveAfterOriginal(object sender, EventArgs e)
{
dynamic gpWindow = DynamicsGpModified.Forms.RmSalesEntry.RmSalesEntry;
FindFirstCustByName(gpWindow);
}
private void RmSalesEntry_LocalPushButtonM147_ClickAfterOriginal(object sender, EventArgs e)
{
dynamic gpWindow = DynamicsGpModified.Forms.RmSalesEntry.RmSalesEntry;
LaunchCustomerLookup(gpWindow);
}
private static void FindFirstCustByName(dynamic gpWindow)
{
RmCustomerMstrTable CustomerMasterTable = Dynamics.Tables.RmCustomerMstr;
//CustomerMasterTable.Key = 2;
string custName = gpWindow.CustomerName.Value;
if (custName != "")
{
TableError err = TableError.NoError;
try
{
err = CustomerMasterTable.GetFirst();
while (err == TableError.NoError)
{
if (CustomerMasterTable.CustomerName.Value.StartsWith(custName, StringComparison.CurrentCultureIgnoreCase))
{
gpWindow.CustomerName.Value = CustomerMasterTable.CustomerName;
gpWindow.CustomerNumber.Value = CustomerMasterTable.CustomerNumber;
break;
}
err = CustomerMasterTable.GetNext();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK);
}
finally
{
CustomerMasterTable.Close();
}
}
}
private void LaunchCustomerLookup(dynamic gpWindow)
{
CustomerLookupForm customerlookup = Dynamics.Forms.CustomerLookup;
//Open the lookup form first.
customerlookup.Open();
//Call the Initialize procedure to set the window fields and fill the window.
//For parameter information, reference the lookup.rtf installed with the GP SDK. All
//paramter information is listed.
customerlookup.Procedures.Initialize.Invoke(2, 0, "", gpWindow.CustomerName.Value, "", "", "", "");
//Set the ReturnToLookup flag to true so we know we called the lookup window.
DynamicsGPAddin.GPAddIn.ReturnToLookup = true;
gpWindowThatLaunchedCustomerLookup = gpWindow;
}
dynamic gpWindowThatLaunchedCustomerLookup;
void custSelectButton_ClickBeforeOriginal(object sender, System.ComponentModel.CancelEventArgs e)
{
//Check the ReturnToLookup flag so we only run the code if the lookup
//was called for our form. If the lookup was called from GP, we don't
//want to do anything.
if (ReturnToLookup == true)
{
//Pressed select button on customer lookup
Microsoft.Dexterity.Applications.SmartListDictionary.CustomerLookupForm custlookupform = SmartList.Forms.CustomerLookup;
//Set our window field equal to what is selected from the scrolling window.
string custid = custlookupform.CustomerLookup.CustomerLookupScroll.CustomerNumber;
string custName = custlookupform.CustomerLookup.CustomerLookupScroll.CustomerName;
//Make sure the Modifiers on the field on the window set to Public.
//vstoolslookupform.CustomerNumber.Text = custid;
gpWindowThatLaunchedCustomerLookup.CustomerNumber.Value = custid;
gpWindowThatLaunchedCustomerLookup.RunValidate();
}
}
}
}