Error when launching reporting menu item from MES

We have a number of custom buttons in MES for launching forms, using C# code tied to the menu item ID. This is the first time I have added a menu item that is of the “report” style, and I am getting the following error:

Application Error

Exception caught in: Erp.Mfg.UIRpt.PCIDContectsReportEntry

Error Detail 
============
Message: Unable to cast object of type 'System.String' to type 'System.Collections.Hashtable'.
Program: Erp.Mfg.UIRpt.PCIDContectsReportEntry.dll
Method: OnFormLoaded

Client Stack Trace 
==================
   at Erp.Mfg.UI.Rpt.PCIDContectsReportEntry.ReportForm.OnFormLoaded()
   at Ice.Lib.Framework.EpiBaseForm.formLoaded()

The report still launches after clicking OK, but I am wondering if this has something to do with the parameters getting passed in on form load. I have searched through the trace and not sure where to go.

Can you post the code? I think you are on the right track in looking at how you are passing the parameters.

I’m not actively passing any parameters…but maybe I need to, or modify what is being passed by default?

// **************************************************
// Custom code for MESMenu
// Created: 10/21/2019 11:49:48 AM
// **************************************************
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Erp.Adapters;
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;

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 edvEmpBasic;

	// End Wizard Added Module Level Variables **

	// Add Custom Module Level Variables Here **	
		EpiButton btnPCIDContentsRep;

	public void InitializeCustomCode()
	{
		btnPCIDContentsRep = (EpiButton)csm. GetNativeControlReference("6dae650b-8ea9-48e2-a4d7-468ce0216d83");

// "1fc1c201-c051-45c6-9d55-612d0e9199c8"
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
		// Begin Wizard Added Variable Initialization
			this.edvEmpBasic = ((EpiDataView)(this.oTrans.EpiDataViews["EmpBasic"]));
			this.edvEmpBasic.EpiViewNotification += new EpiViewNotification(this.edvEmpBasic_EpiViewNotification);

		// End Wizard Added Variable Initialization

		// Begin Wizard Added Custom Method Calls

		// End Wizard Added Custom Method Calls
			this.btnPCIDContentsRep.Click += new System.EventHandler(this.btnPCIDContentsRep_Click);
	}

	public void DestroyCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
		// Begin Wizard Added Object Disposal
			this.edvEmpBasic.EpiViewNotification -= new EpiViewNotification(this.edvEmpBasic_EpiViewNotification);
			this.edvEmpBasic = null;

		// End Wizard Added Object Disposal

		// Begin Custom Code Disposal

		// End Custom Code Disposal		
			this.btnPCIDContentsRep.Click -= new System.EventHandler(this.btnPCIDContentsRep_Click);

	}

	private void MESMenu_Load(object sender, EventArgs args)
		{
			// Add Event Handler Code
				btnPCIDContentsRep.ReadOnly = true;
		}

	private void btnPCIDContentsRep_Click(object sender, System.EventArgs args)
	{
		ProcessCaller.LaunchForm(this.oTrans, "AMRP1000");
	}

	private void edvEmpBasic_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))
		{
			if ((args.Row > -1))
			{
				btnPCIDContentsRep.ReadOnly = false;
			}
			else
			{
				btnPCIDContentsRep.ReadOnly = true;
			}
		}
	}

}

I was able to reproduce the error. Try adding a blank launch form options and passing it in the call. Killed the error for me.

LaunchFormOptions lfo = new LaunchFormOptions();
ProcessCaller.LaunchForm(this.oTrans, “Erp.Mfg.UIRpt.PCIDContectsReportEntry”,lfo);

(insert your menuID)
(Sorry, this text did not want to get formatted)

Not sure exactly why, but something related to the launch form options being a hashtable. Maybe a blank string was being passed instead, not sure. Maybe someone else can shed some light on why this is happening.

1 Like

Adam, thank you so much! I have set up LFO’s before but didn’t even think of that. Much appreciated.

1 Like

No problem! Lucky (educated) guess on my part.