C# Execute PerformClick() on a Submit Button Not Firing

I am trying to fire the PerformClick() event of the submit button (btnUpdate) in the Price List Inquiry screen and it doesn’t appear to be firing.

1.I started out by creating a EpiButton reference with the GUID named btnSubmit, then calling the code btnSubmit.PerformClick(); The IDE didn’t complain but it didn’t seem to do anything on the form.
2. To see if it was being called at all, I attached my own custom event listener to the btnSubmit object to detect if it was being called.
a. When I clicked the submit button manually, my event listener code was in fact being called.
b. When I programatically executed btnSubmit.PerformClick() my event listener code was not being called and it appears that the .PerformClick() was still doing nothing.
3. I tried instantiating the btnSubmit object at the script level as well as at the function level. I know I have a good reference to the submit button because I can change it’s text and so on. I have also initialized the submit object reference in the InitiliazeCustomCode() level as well as trying to initialize it at the function level in which I am using it.

I am new to Epicor and Epicor development but not to software development.

Shouldn’t the following code work?

EpiButton btnSubmit = (EpiButton)csm.GetNativeControlReference(“535f48e2-e049-4eea-93ba-322e7ade6b56”);
btnSubmit.PerformClick();

@Ethan:

Do you mind posting the rest of your code? And when you test it in the customization script editor, does it compile successfully?

@Matthew_Morgan - yes, it compiles successfully.

Code is below (I commented out the event handler call and a few other items during testing):

// **************************************************
// Custom code for PriceListInquiryForm
// Created: 6/18/2013 10:48:31 AM
// **************************************************

extern alias Erp_Contracts_BO_Part;
extern alias Erp_Contracts_BO_Warehse;
extern alias Erp_Contracts_BO_Customer;
extern alias Erp_Contracts_BO_Currency;

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

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 edvPart;
	private string lastValue ="";
	private EpiButton subButton;
	// 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.edvPart = ((EpiDataView)(this.oTrans.EpiDataViews["Part"]));
		this.edvPart.EpiViewNotification += new EpiViewNotification(this.edvPart_EpiViewNotification);
		subButton = (EpiButton)csm.GetNativeControlReference("535f48e2-e049-4eea-93ba-322e7ade6b56");
		
		// End Wizard Added Variable Initialization

		// Begin Wizard Added Custom Method Calls

		// 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.edvPart.EpiViewNotification -= new EpiViewNotification(this.edvPart_EpiViewNotification);
		this.edvPart = null;
		this.lastValue = null;
		this.subButton = null;
		// End Wizard Added Object Disposal

		// Begin Custom Code Disposal

		// End Custom Code Disposal
	}


	private void edvPart_EpiViewNotification(EpiDataView view, EpiNotifyArgs args)
	{
		// ** Argument Properties and Uses **
		// view.dataView[args.Row]["FieldName"]
		// args.Row, args.Column, args.Sender, args.NotifyType
		// NotifyType.Initialize, NotifyType.AddRow, NotifyType.DeleteRow, NotifyType.InitLastView, NotifyType.InitAndResetTreeNodes
		if (( args.NotifyType == EpiTransaction.NotifyType.Initialize))
		{
			EpiTextBox descText = (EpiTextBox)csm.GetNativeControlReference("fdc538aa-b1be-415a-a308-272b27af24d5");
			string newValue = descText.Text;
			if(lastValue != newValue && newValue != "")
			{		
				lastValue = newValue;
				MessageBox.Show("Initializing with "+ newValue);

				//I can add a new event handler that piggy backs on the .Click event VVV				
				//subButton.Click += new EventHandler(ClickSubmit);
				subButton.PerformClick();
			}
		}
	}

//	private void ClickSubmit(object sender, EventArgs args)
	//{
		//MessageBox.Show("I am trying to submit now...");
		//subButton.Click -= new EventHandler(ClickSubmit);
	//}
}

I see the MessageBox popping up saying "Initializing with "+newValue and I am able to manipulate the submit button (not shown in this code), so I am not sure what gives.

2022-03-29_8-22-38

Ok cool, I’m still not sure what specific event you want to trigger that button click though.

I want to fire the submit button click event as seen in the second photo in my previous comment.

Basically when a given criteria is met, I want to programatically execute the submit button’s click event. I hope that makes sense :slight_smile:

That helps a little, but what action or event do you want to check the criteria? Right when the form loads or something else? Otherwise I’m not sure I follow.

I can appreciate that you are trying to wrap your head around when my criteria is met and when I am firing that code. That portion of the code works as I expect it to - regardless, the code is being executed from the following snippet:

	private void edvPart_EpiViewNotification(EpiDataView view, EpiNotifyArgs args)
	{
		// ** Argument Properties and Uses **
		// view.dataView[args.Row]["FieldName"]
		// args.Row, args.Column, args.Sender, args.NotifyType
		// NotifyType.Initialize, NotifyType.AddRow, NotifyType.DeleteRow, NotifyType.InitLastView, NotifyType.InitAndResetTreeNodes
		if (( args.NotifyType == EpiTransaction.NotifyType.Initialize))
		{
			EpiTextBox descText = (EpiTextBox)csm.GetNativeControlReference("fdc538aa-b1be-415a-a308-272b27af24d5");
			string newValue = descText.Text;
			if(lastValue != newValue && newValue != "")
			{		
				lastValue = newValue;
				MessageBox.Show("Initializing with "+ newValue);

				//I can add a new event handler that piggy backs on the .Click event VVV				
				//subButton.Click += new EventHandler(ClickSubmit);
				subButton.PerformClick();
			}
		}
	}`Preformatted text`

I am seeing the messagebox pop up showing “Initializing with …” and as I mentioned earlier, I added an event handler (which is commented out in this version) that I was able to see whether the subButton.PerformClick() was being triggered. It appears that it is not being triggered as I would have hoped, even though other code within the same code block is.

I hope this helps.

I’m not following this thread closely, but I would suggest an alternate perspective.

Avoid programatically interacting with the user interface via code if you can. In this case, you are hooking a UI event onto a very generic data view event, which could have a lot of unintended behavior. For instance, if this event fires prior to the UI control being initialized, it won’t perform the click.

The click itself likely does something and that’s what I’d recommend looking into replicating via a careful analysis of the trace logs when clicking the button. Then, you can invoke that action (independent of a UI button click) and can make sure that the invocation of it is surgical and not tied to a generic event like the initialization of a data view.

@Aaron_Moreng I appreciate your contribution, sometimes looking at it from an alternate perspective is the way to go! I am a noob when it comes to Epicor but not software development so I can appreciate that Epicor has a ton of it’s own idiosyncrasies/nuances that I am totally unaware of, which may necessitate a different perspective.

I would like to exhaust this approach before I give up and try a different angle. I know the submit button is instantiated (I can manipulate the button, I just can’t fire it’s click event).

At very least I want to get to the bottom of why it isn’t working. Nothing worse than walking away from a problem not knowing why it didn’t work.

1 Like

If I don’t know why it isn’t working, I am bound to repeat this mistake.

Perhaps try referencing the native control inside your data view initialize event rather than upon form load. I wonder if the private modifier is messing with it

I will give that a try, much appreciated!

I’m digging through some ancient code I wrote years ago to try and find an example where I did the same thing. Anyways you’re on the right track (for this method :wink: )

1 Like
private void txtLotNumScan_ValueChanged(object sender, System.EventArgs args)
	{
		// ** Place Event Handling Code Here **
		EpiTextBox partNum = (EpiTextBox)csm.GetNativeControlReference("52c8193e-d045-4605-b11f-85d0fe8b54a8");
		EpiTextBox lotNum = (EpiTextBox)csm.GetNativeControlReference("46567b2e-6bc0-4967-be35-a0ec6843838f");
		EpiTextBox tbxDescription = (EpiTextBox)csm.GetNativeControlReference("7c422ab4-6df2-4e5e-ad82-196021b36a2a");
		string scanLot = txtLotNumScan.Text.ToString();
		//MessageBox.Show(scanLot);
		if (scanLot != null)
		{
		//if using dynamic query...
		DynamicQueryAdapter qryPartLot = new DynamicQueryAdapter(oTrans); 
		QueryExecutionDataSet exDS = new QueryExecutionDataSet();
		QueryExecutionDataSet parameters = new QueryExecutionDataSet();
		
		DataRow paramRow = parameters.ExecutionParameter.NewRow();
		paramRow["ParameterID"] = "LotNum";
    	paramRow["ParameterValue"] = scanLot;		
    	paramRow["ValueType"] = "nvarchar(30)";
    	paramRow["IsEmpty"] = "False";
		parameters.ExecutionParameter.Rows.Add(paramRow);
			
		qryPartLot.BOConnect();
		qryPartLot.ExecuteByID("HH_ReturnPartNum", parameters);	
	    DataSet dsPartLot = qryPartLot.QueryResults;
		qryPartLot.Dispose();	
			
		foreach (DataRow dr in dsPartLot.Tables[0].Rows)
			{
			//MessageBox.Show(dr["PartLot_PartNum"].ToString());
			partNum.Value = dr["PartLot_PartNum"].ToString();				
			}	
		partNum.Focus();
		lotNum.Focus();
		lotNum.Value = scanLot;
		lotNum.Focus();
		tbxDescription.Focus();
		}

Example similar to yours, not using a button event but using textbox control events of the form.