Loading an Adapter via a custom button and custom search parameter

Dear all,

I am new to Wizard Events and have very limited knowledge of how Adapters work inside Epicor but have a relatively good programming experience in C#. Unfortunately Form Event Wizard is mainly in VB so please bear with me.
This is my code:

// **************************************************
// Custom code for SalesOrderForm
// Created: 2020-10-27 7:11:06 PM
// **************************************************

extern alias Erp_Contracts_BO_AlternatePart;
extern alias Erp_Contracts_BO_SalesOrder;
extern alias Erp_Contracts_BO_Quote;
extern alias Erp_Contracts_BO_Part;
extern alias Erp_Contracts_BO_Customer;
extern alias Erp_Contracts_BO_RMAProc;
extern alias Erp_Contracts_BO_OrderDtlSearch;
extern alias Erp_Contracts_BO_OrderHist;
extern alias Erp_Contracts_BO_QuoteDtlSearch;
extern alias Erp_Contracts_BO_SerialNumberSearch;
extern alias Erp_Contracts_BO_ShipTo;

using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Erp.Adapters;
using Erp.UI;
using Ice.Lib;
using Ice.Adapters;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;

using Erp.UI;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;

public class Script
	// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
	// Begin Wizard Added Module Level Variables **
		private EpiDataView edvUD07;
		private SalesOrderAdapter adSO;
	// End Wizard Added Module Level Variables **

	// Add Custom Module Level Variables Here **

	public void InitializeCustomCode()
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
		// Begin Wizard Added Variable Initialization
		this.edvUD07 = ((EpiDataView)(this.oTrans.EpiDataViews["UD07"]));
		this.adSO = new SalesOrderAdapter(this.oTrans);
		// End Wizard Added Variable Initialization

		// Begin Wizard Added Custom Method Calls

		this.epiButtonC1.Click += new System.EventHandler(this.epiButtonC1_Click);
		// End Wizard Added Custom Method Calls

	public void DestroyCustomCode()
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
		// Begin Wizard Added Object Disposal

		this.epiButtonC1.Click -= new System.EventHandler(this.epiButtonC1_Click);
		// End Wizard Added Object Disposal

		// Begin Custom Code Disposal

		// End Custom Code Disposal

	private void epiButtonC1_Click(object sender, System.EventArgs args)
		// ** Place Event Handling Code Here **
		EpiTextBox txtSO = ((EpiTextBox)csm.GetNativeControlReference("4fceeeec-518c-4256-932e-34a4c1a584ee"));
		bool recSelected;
		string whereClause = string.Empty;
		System.Data.DataSet dsSalesOrderAdapter = Ice.UI.FormFunctions.SearchFunctions.listLookup(this.oTrans,"SalesOrderAdapter", out recSelected, true, whereClause);
		System.Data.DataRow adapterRow = dsSalesOrderAdapter.Tables[0].Rows[0];
		txtSO.Text = adapterRow["OrderNum"].ToString();
		this.edvUD07.dataView[edvUD07.Row]["ShortChar01"] = dsSalesOrderAdapter.Tables[0].Rows[0]["OrderNum"].ToString();

For starters I wanted to load same adapter that Sales Order Entry uses and fill the form. Later my was to use the same adapter to load but use a different parameter to search. We have some SalesForce opportunity IDs that I wish to search based on those instead of using OrderNum.

The current status is that when I click on the button, it launches the search window and when I select the order number, instead of populating the form, it shows an error:


The details of the error shows this:

I understand this can be done quite easily using quick search, but I was wondering if I could achieve it this way as well.
I would appreciate it if you can help me achieve my goal.


Have you tried debugging it in Visual Studio? That’s usually a good way to figure out exactly where your null object is.

txtSO.Text = adapterRow["OrderNum"].ToString();

I wouldn’t do this. I would write it to the Form’s EpiDataView instead. I’ve had bad effects writing directly to a bound textbox.

Hi @Doug.C,

Thank you for your response. I am not familiar with any method to test this in Visual studio for debugging purposes. Can you please direct me to a reference so that I can learn?

Also regarding the code that you suggested some adjustment, can you please help me understand it better?

I honestly am not sure what this part means and I appreciate your help in advance :slight_smile:

Kind Regards,

You can debug with Visual Studio by checking the box in the bottom left corner of the select customization screen:

As far as the example code goes, this is what I do to generate the next available UPC # for our parts:

EpiDataView edvPartUOM = ((EpiDataView)(this.oTrans.EpiDataViews["PartUOM"]));

edvPartUOM.dataView[edvPartUOM.Row]["UPC12"] = String.Format("{0}{1}",strCode, CheckDigit);

This will put the UPC into the UOMs tab on the part maintenance form. You would have to alter it to fit the form you are on. If you search this forum for BeginEdit or EndEdit there will be a lot of examples to look at.

Thank you very much @Doug.C !