Custom code only running once per session

I had found a thread that seemed to solve this issue: MES Form_Load() only triggers once per session - #3 by BKoch - ERP 10 - Epicor User Help Forum

However, this doesn’t appear to work. What I am doing is passing some data using LFO from the MES Menu to a BAQ Report Form (to fill in the fields automatically). It works the first time, but if I close the BAQ Report Form and try again, it opens the form without the fields filled in. I have to close and re-open MES to get it pass data again.

What is strange is that I have some other code that passes a barcode using LFO from the MES Menu to the Start Production Activity Form, and that works every time.

This is my current code:

MES Menu:

LaunchFormOptions lfo2 = new LaunchFormOptions();

private void btnPrintTag_Click(object sender, System.EventArgs args)
{
	var view = ((EpiDataView)(this.oTrans.EpiDataViews["LaborDtl"]));
	if(view.Row >= 0)
	{
		string job = view.dataView[view.Row]["JobNum"].ToString();
		string asm = view.dataView[view.Row]["AssemblySeq"].ToString();
		string opr = view.dataView[view.Row]["OprSeq"].ToString();
		string parameters = "P." + job + "." + asm + "." + opr;
		lfo2.IsModal = false;
		lfo2.SuppressFormSearch = true;
		lfo2.ContextValue = parameters;
		ProcessCaller.LaunchForm(this.oTrans, "P9999", lfo2);
		this.oTrans.RefreshLaborData();
	}
}

BAQ Report Form:

private void BAQReportForm_Load(object sender, EventArgs e)
{
	// Add Event Handler Code
	if(BAQReportForm.LaunchFormOptions != null)
	{
		object parametersObj = BAQReportForm.LaunchFormOptions.ContextValue;
		// Convert parameters (object to string)
		string parameters = parametersObj.ToString();
		// Split string into parts
		var items = parameters.Split('.');
		string job = items[1];
		string asm = items[2];
		string opr = items[3];
		// Fill fields
		var view = ((EpiDataView)(this.oTrans.EpiDataViews["ReportParam"]));
		if(view.Row >= 0)
		{
			view.dataView[view.Row].BeginEdit();
			view.dataView[view.Row]["field1"] = job;
			view.dataView[view.Row]["field2"] = asm;
			view.dataView[view.Row]["field3"] = opr;
		}
	}
}

As I said, I have also tried using the Initialize Custom Code method, to no avail.

Have you tested how many rows exist in view.dataView?

I don’t know how to test that. Would that be on the MES menu form or on the Report form?

Haha good point. I am thinking to start by looking to see if for some reason, the report form has more than one row of report params.

var view = ((EpiDataView)(this.oTrans.EpiDataViews[“ReportParam”]));
var howManyRows = view.dataView.Count

If I add it to the Report form, I get “1” the first time it is run, and nothing pops up on the second time. It just seems like it won’t even run the custom code…

I dont know that it will make a difference, but it may be worthwhile to move the creation of the lfo into your process so you get a new one every time.

I think in the report. I’d also show a msg to see the state of lfo and it’s context value (ensure they arent null)

I think I tried that before, I tried it now and it didn’t work.

When I count the DataView rows in the MES form, it gives me the correct number every time.

Change the caption of your customized report form so you can ensure it is in fact loading the customization.

Or add a msgbox on load

Also, when you tested the rows on the report form, did you do it with no conditions - for example. you didnt place it after:
if(view.Row >= 0) {
or the check for lfo

I tested it with no conditions.

If I put a message box on Load, it will only show up once…if I click the button in MES to run the code again, it won’t show up.

Silly question - do you have a custom button sitting over a native one on the MES screen?

No, it doesn’t have anything behind it.

I’m grasping at straws but try this:

lfo2.IsModal = true;
var reportForm=(EpiBaseForm)ProcessCaller.LaunchForm(this.oTrans, "P9999", lfo2);
reportForm.Dispose();

I’m getting an “Object reference not set to an instance of an object” error, along with the same behavior as before.

Did you ever determine if the customization is running (with either a caption change or msg box on load)?

I tried a MessageBox both at InitializeCustomCode and at BAQReportForm_Load, and it won’t show up. I don’t think the code runs after it’s been run once in a session. It’s bizarre.

Have you tried to step debug it using visual studio?

I’m not sure how to do that. I don’t have Visual Studio installed, all I have is the Visual Studio Remote Debugger, but it says I don’t have access to configure it.

I’ve reached out to our IT department to get the program installed.

While I wait for VS, I tried adding a timer in InitializeCustomCode(), but that hasn’t worked either. Is there something about the Report form where it needs to be reset or something to allow the code to run again?

My inital though was that there might be additional param rows, however, this seems more like the customization isnt being run at all. Trying a trace might be worthwhile. You can see the calls and the params being sent to make sure everything looks legit.

1 Like

I did a trace for both cases (working and not working), and can’t find where it’s passing the parameters in either. I did notice that the following Methods did not show up on the trace for the “not working” case: GetClassInformation (fired twice), GetAttributes (fired twice), GetList, GetAvailableDocumentTypes, and
GetReportsThatDefaultToEmfRenderFormat.

tracePacket_notworking.docx (17.5 KB)
tracePacket_working.docx (18.3 KB)