UD05 Entry C# Customization - Object reference not set to an instance of an object - Help Needed

I am adding two data views to an UD05 entry item. The test code function says that there is nothing wrong. However, when I close and reopen the UD05 entry screen with the customization active I get the following error:

I believe this error is caused by the line “InitializeUD05Adapter();” within the Initialize Custom Code block. The reason for this is that when I comment out that section of code everything seems to work as normal. I have included both the Initialize Custom Code block and the InitializeUD05Adapter block below.

As always thanks for the help!

public void InitializeCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
		// Begin Wizard Added Variable Initialization

		// End Wizard Added Variable Initialization

		// Begin Wizard Added Custom Method Calls

		// End Wizard Added Custom Method Calls

		//eb1:

		InitializeUD05Adapter();
		this._Key1UD05 = string.Empty;
		this._Key2UD05 = string.Empty;
		this._Key3UD05 = string.Empty;
		this._Key4UD05 = string.Empty;
		this._Key5UD05 = string.Empty;
		this._Key1UD05_2 = string.Empty;
		this._Key2UD05_2 = string.Empty;
		this._Key3UD05_2 = string.Empty;
		this._Key4UD05_2 = string.Empty;
		this._Key5UD05_2 = string.Empty;
		
	}

private void InitializeUD05Adapter()
	{
		// Create an instance of the Adapter.
		this._UD05Adapter = new UD05Adapter(this.oTrans);
		this._UD05Adapter.BOConnect();

		this._UD05Adapter_2 = new UD05Adapter(this.oTrans);
		this._UD05Adapter_2.BOConnect();


		// Add Adapter Table to List of Views
		// This allows you to bind controls to the custom UD Table
		this._edvUD05 = new EpiDataView();
		this._edvUD05.dataView = new DataView(this._UD05Adapter.UD05Data.UD05);

		this._edvUD05_2 = new EpiDataView();
		this._edvUD05_2.dataView = new DataView(this._UD05Adapter_2.UD05Data.UD05);

		//this._edvUD05.AddEnabled = true;
		//this._edvUD05.AddText = "New UD05";
		this._edvUD05.AddEnabled = false;

		this._edvUD05_2.AddEnabled = false;

		if ((this.oTrans.EpiDataViews.ContainsKey("UD05View") == false))
		{
			this.oTrans.Add("UD05View", this._edvUD05);
		}
		if ((this.oTrans.EpiDataViews.ContainsKey("UD05View_2") == false))
		{
			this.oTrans.Add("UD05View_2", this._edvUD05_2);
		}

		// Initialize DataTable variable
		this.UD05_Column = this._UD05Adapter.UD05Data.UD05;
		this.UD05_Column_2 = this._UD05Adapter_2.UD05Data.UD05;

		// Initialize EpiDataView field.
		this._edvVendorDetail = ((EpiDataView)(this.oTrans.EpiDataViews["VendorDetail"]));

		// Set the parent view / keys for UD child view
		string[] parentKeyFields = new string[1];
		string[] childKeyFields = new string[1];
		parentKeyFields[0] = "VendorNum";
		childKeyFields[0] = "Key1";
		this._edvUD05.SetParentView(this._edvVendorDetail, parentKeyFields, childKeyFields);

		string[] parentKeyFields_2 = new string[1];
		string[] childKeyFields_2 = new string[1];
		parentKeyFields_2[0] = "VendorNum";
		childKeyFields_2[0] = "Key1";
		this._edvUD05_2.SetParentView(this._edvVendorDetail, parentKeyFields_2, childKeyFields_2);

		if ((this.oTrans.PrimaryAdapter != null))
		{
			this.oTrans.PrimaryAdapter.GetCurrentDataSet(Ice.Lib.Searches.DataSetMode.RowsDataSet).Tables.Add(this._edvUD05.dataView.Table.Clone());
		}

	}

I have changed alot of the code and am now looking at something much simpler.

	private UD05Adapter _ud05Adapter_2;
	private DataTable UD05_Column_2;
	private EpiDataView _edvUD05_2;
	private UD05Adapter _ud05Adapter;
	private DataTable UD05_3Column;
	private EpiDataView _edvUD05;
	public void InitializeCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
		// Begin Wizard Added Variable Initialization

		this.AutoAttachUD05_DataView = this.AutoAttachUD05_Row.dataView;
		this.AutoAttachUD05_DataView.ListChanged += new ListChangedEventHandler(this.AutoAttachUD05_DataView_ListChanged);
		// End Wizard Added Variable Initialization

		// Begin Wizard Added Custom Method Calls
		this._ud05Adapter = new UD05Adapter(this.oTrans);
		this._ud05Adapter.BOConnect();

		this._ud05Adapter_2 = new UD05Adapter(this.oTrans);
		this._ud05Adapter_2.BOConnect();
		this._edvUD05 = new EpiDataView();
		this._edvUD05.dataView = new DataView(this._ud05Adapter.UD05Data.UD05);

		this._edvUD05_2 = new EpiDataView();
		this._edvUD05_2.dataView = new DataView(this._ud05Adapter_2.UD05Data.UD05);
		// End Wizard Added Custom Method Calls

		this._edvUD05.AddEnabled = false;

		this._edvUD05_2.AddEnabled = false;

		if ((this.oTrans.EpiDataViews.ContainsKey("UD05View") == false))
		{
			this.oTrans.Add("UD05View", this._edvUD05);
		}
		if ((this.oTrans.EpiDataViews.ContainsKey("UD05View_2") == false))
		{
			this.oTrans.Add("UD05View_2", this._edvUD05_2);
		}
		// Initialize DataTable variable
		this.UD05_Column = this._ud05Adapter.UD05Data.UD05;
		this.UD05_Column_2 = this._ud05Adapter_2.UD05Data.UD05;


	}

The issue I have now is that the UD05_View and UD05_View2 are not populating.

@josecgomez,
Any clue what I am missing past this, or why the data views are not populating the epigrids?

Got the grids to publish out using the following code:

private void GetUD05Data_2(string key1, string key2, string key3, string key4, string key5)
	{
		if ((this._Key1UD05_2 != key1) || (this._Key2UD05_2 != key2) || (this._Key3UD05_2 != key3) || (this._Key4UD05_2 != key4) || (this._Key5UD05_2 != key5))
		{
			// Build where clause for search.
			//string whereClause = "Key1 = \'" + key1 + "\' And Key2 = \'" + key2 + "\' And Key3 = \'" + key3 + "\' And Key4 = \'" + key4 + "\'";
			string whereClause = "Key1 = \'" + key1 + "\' And Key2 = \'" + key2 + "\'";
			//MessageBox.Show("whereClause: " + whereClause);

			System.Collections.Hashtable whereClauses = new System.Collections.Hashtable(1);
			whereClauses.Add("UD05", whereClause);

			// Call the adapter search.
			SearchOptions searchOptions = SearchOptions.CreateRuntimeSearch(whereClauses, DataSetMode.RowsDataSet);
			this._ud05Adapter_2.InvokeSearch(searchOptions);

			if ((this._ud05Adapter_2.UD05Data.UD05.Rows.Count > 0))
			{
				this._edvUD05_2.Row = 0;
			} else
			{
				this._edvUD05_2.Row = -1;
			}

			// Notify that data was updated.
			this._edvUD05_2.Notify(new EpiNotifyArgs(this.oTrans, this._edvUD05_2.Row, this._edvUD05_2.Column));

			// Set key fields to their new values.
			this._Key1UD05_2 = key1;
			this._Key2UD05_2 = key2;
			this._Key3UD05_2 = key3;
			this._Key4UD05_2 = key4;
			this._Key5UD05_2 = key5;

		}

	}
	private void GetUD05Data(string key1, string key2, string key3, string key4, string key5)
	{
		if ((this._Key1UD05 != key1))
		{
			// Build where clause for search.
			//string whereClause = "Key1 = \'" + key1 + "\' And Key2 = \'" + key2 + "\' And Key3 = \'" + key3 + "\' And Key4 = \'" + key4 + "\'";
			string whereClause = "Key1 = \'" + key1 + "\' And Key2 = \'" + key2 + "\'";
//MessageBox.Show("whereClause: " + whereClause);

			System.Collections.Hashtable whereClauses = new System.Collections.Hashtable(1);
			whereClauses.Add("UD05", whereClause);

			// Call the adapter search.
			SearchOptions searchOptions = SearchOptions.CreateRuntimeSearch(whereClauses, DataSetMode.RowsDataSet);
			this._ud05Adapter.InvokeSearch(searchOptions);

			if ((this._ud05Adapter.UD05Data.UD05.Rows.Count > 0))
			{
				this._edvUD05.Row = 0;
			} else
			{
				this._edvUD05.Row = -1;
			}

			// Notify that data was updated.
			this._edvUD05.Notify(new EpiNotifyArgs(this.oTrans, this._edvUD05.Row, this._edvUD05.Column));

			// Set key fields to their new values.
			this._Key1UD05 = key1;
			this._Key2UD05 = key2;
			this._Key3UD05 = key3;
			this._Key4UD05 = key4;
			this._Key5UD05 = key5;

		}

	}

Now I need to create a baq data view and use the results from it to select what is selected in ud05 instead of picking each record individually.

Using the link below I now get the results from the baq to show up. The issue is that the results are posted into my second epigrid and overwriting the data view that should be there.

What Im looking for right now is a way to get a search dialog to launch and show the results of the baq. Then based on the users selection filter the corresponding data that is in UD05.

Had a call with an Epicor customization team member and got 99% of the way there.

The issue I have now is that when I click save the UD05 table is not updated. If I click save, change what data I have selected and save again then the original data that was changed/updated saves correctly. Below is the code I am using to push the save.

private void UndoUD05Changes()
	{
		this._ud05Adapter.UD05Data.RejectChanges();
		this._ud05Adapter_2.UD05Data.RejectChanges();

		// Notify that data was updated.
		this._edvUD05.Notify(new EpiNotifyArgs(this.oTrans, this._edvUD05.Row, this._edvUD05.Column));
		this._edvUD05_2.Notify(new EpiNotifyArgs(this.oTrans, this._edvUD05_2.Row, this._edvUD05_2.Column));
	}

	//eb1:
	private void ClearUD05Data()
	{
		this._Key1UD05 = string.Empty;
		this._Key2UD05 = string.Empty;
		this._Key3UD05 = string.Empty;
		this._Key4UD05 = string.Empty;
		this._Key5UD05 = string.Empty;

		this._Key1UD05_2 = string.Empty;
		this._Key2UD05_2 = string.Empty;
		this._Key3UD05_2 = string.Empty;
		this._Key4UD05_2 = string.Empty;
		this._Key5UD05_2 = string.Empty;
		baqComboC1.Value = string.Empty;

		this._ud05Adapter.UD05Data.Clear();
		this._ud05Adapter_2.UD05Data.Clear();

		// Notify that data was updated.
		this._edvUD05.Notify(new EpiNotifyArgs(this.oTrans, this._edvUD05.Row, this._edvUD05.Column));
		this._edvUD05_2.Notify(new EpiNotifyArgs(this.oTrans, this._edvUD05_2.Row, this._edvUD05_2.Column));

	}

	private void SaveUD05Record()
	{
		// Save adapter data
		this._ud05Adapter.Update();
		this._ud05Adapter_2.Update();
	}

	private void baseToolbarsManager_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs args)
	{
		switch (args.Tool.Key)
		{
			//case "EpiAddNewNew UD05":
			//	GetNewUD05Record();
			//	break;
			case "SaveTool":
				SaveUD05Record();
				MessageBox.Show("AAAAAAAAH");
				break;

			case "ClearTool":
				ClearUD05Data();
				break;

			case "UndoTool":
				UndoUD05Changes();
				break;

			case "RefreshTool":
				ClearUD05Data();
				//string vendornum = args.CurrentView.dataView[args.CurrentRow]["VendorNum"].ToString();
				string vendornum = VendorDetail_DataView[0]["VendorNum"].ToString();
				GetUD05Data(vendornum, "SupCustApp", string.Empty, string.Empty, string.Empty);
				GetUD05Data_2(vendornum, "SupRegApp", string.Empty, string.Empty, string.Empty);
				break;

		}
	}

Conclusion

The original error was caused by a naming convention error. The error with the customization not saving was that I was using oTran.Update; instead of my declared _ud05Adapter.Update;. As soon as the swap was made it worked like a charm. The moral of the story, don’t fat finger when coding, it’ll save you a lot of headaches.

Huge props to Dan Godfrey for sitting on the phone with me for an hour and getting me where I needed to be. Couldn’t have got it done without him!

1 Like