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(); } } } }
Thanks! It works now....I was so close.
Now to fix all the Email option tables.
rmCustomerModifier does NOT update these properly.
So many bugs with rmCustomerModifier including broken error trapping it isn't even funny.
Hi Scott
Please let me know what issues you had. Email support at WinthropDC dot com.
We have many satisfied customers with zero issues. In fact their systems run better with GP Power Tools installed as it not only adds lots of functionality, it also fixes a number of bugs in GP.
Regards
David
Thanks, David
I tried to install the GP power tools before and had issues, I will definitely give it a try again now that I've cleaned up the Dev and Prog GP environments here...
I'll try your suggestion for the code although I think that's what I had originally and I was experimenting using trial and error trying to get anything to work.
I'll have to try it in a bit, I'm sorry I have a customer appointment.
I also noticed another bug. You need to register an event when the lookup window closes to clear the ReturnToLookup value.
Hi Scott
Line 165
gpWindowThatLaunchedCustomerLookup.RunValidate();
Should be
gpWindowThatLaunchedCustomerLookup.CustomerNumber.RunValidate();
That should get it working...
PS: The code to handle this with GP Power Tools triggers would be much simpler, required no deployment and be much easier to maintain. See http://WinthropDC.com/GPPT
Regards
David
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156