Launch form with current EmpID via code?

Hello,

When you launch Time & Expense Entry within standard Epicor, if the current user has an employee record attached to it, T&E will default to that EmpID when it opens. However, if you add T&E to a button in MES, it does not default to the current employee. Is there a way I can make this happen?

I see in the Object explorer that there is a TimeExpenseForm.Session.EmployeeID, but I don’t know how to use that to do what I need.

Any help would be greatly appreciated.

You can send different parms to open in Time or Expense mode but in general you can make a hashtable and add the following keys to pass to LaunchFormOpts.ValueIn:

key | valuetype
“type” | string “T” for TIME
“empID” | string
“laborDtlSeq” | string
“laborDate” | DateTime
“mode” | string

                Hashtable YourHashtable = new Hashtable();
                YourHashtable.Add("Key", value); //etc, etc
                LaunchFormOptions lfo = new LaunchFormOptions();
                lfo.ValueIn = YourHashtable;

//now pass to Form Open call

1 Like

Yup @Chris_Conn that is usually the way to get a form to load a record with its key value available and perform and auto search. - although for the sake of completeness with your code snippet, and generically applying it to all Epicor forms!! ;): - it doesn’t have to be a hashtable and may be a tilda delimited list or a simple string value, something like lfo.ValueIn = “100~1” or just lfo.ValueIn=“100”, depending on the form that is being loaded. Worst comes to worst - you can decompile the UI assembly and look at the launch class.

Hey @Chris_Conn & @kjavid, thanks for taking the time to reply. Would you be able to give me a little more detail? I’m not really a programmer, so some of this went right over my head.

Right now I have this code with launches T&E.

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

I decompiled the Epr.UI.App.TimeAndExpenseEntry.dll, but I got lost in what to look for.

Norman, create a custom button. Add a CLICK handler using the wizard. For the code try this:

                string yourEMP = ((Session)oTrans.Session).EmployeeID;
                Hashtable YourHashtable = new Hashtable();
                YourHashtable.Add("type","T");
                YourHashtable.Add("empID",yourEMP);
                YourHashtable.Add("laborDate",DateTime.Now);
                LaunchFormOptions lfo = new LaunchFormOptions();
                lfo.ValueIn = YourHashtable;

                ProcessCaller.LaunchForm(this.oTrans, "UDTimEnt", lfo);

Have a look at this in the disassembly:
private void FormLoadFromApprovalEntry()

2 Likes

That’s OK @nhutchins as you can see in the “public override object LaunchForm(etc)” method is being passed an object of type TimeExpApprovalArgs. If you click in that type you will be able to see the fields available to set in your launch form options.

Every thing else looks fine!

1 Like

Hey @Chris_Conn,

Do I need some Using statements? I’m getting compile errors.

Error: CS0246 - line 153 (729) - The type or namespace name ‘Session’ could not be found (are you missing a using directive or an assembly reference?)
Error: CS0246 - line 154 (730) - The type or namespace name ‘Hashtable’ could not be found (are you missing a using directive or an assembly reference?)
Error: CS0246 - line 154 (730) - The type or namespace name ‘Hashtable’ could not be found (are you missing a using directive or an assembly reference?)

ohh, just I figured out the Hashtable one. What do I need to be able to use Session?

using Ice.Core; (also be sure to import it)

if you just want a quick and dirty test, you can do:
string yourEMP = “AworkingEmpIdHere”;

So I’m getting an error, which I think is the LaunchForm syntax. I get it whether I hard code an EmpID or use the session EmpID. Here’s the code, and the error is below. Any thoughts?

private void btnLaunchTimeEntry_Click(object sender, System.EventArgs args)
	{

		string yourEMP = "407"; //((Session)oTrans.Session).EmployeeID;
                Hashtable YourHashtable = new Hashtable();
                YourHashtable.Add("type","T");
                YourHashtable.Add("empID",yourEMP);
                YourHashtable.Add("laborDate",DateTime.Now);
                LaunchFormOptions lfo = new LaunchFormOptions();
                lfo.ValueIn = YourHashtable;

                ProcessCaller.LaunchForm(this.oTrans, "UDTimEnt", lfo);
		//ProcessCaller.LaunchForm(this.oTrans, "UDTimEnt");
		}

Application Error

Exception caught in: Ice.Lib.EpiClientLib

Error Detail

Message: The process caller failed to invoke method LaunchForm in Ice.Lib.App.Launch in Erp.UI.TimeAndExpenseEntry.dll
Inner Exception Message: Exception has been thrown by the target of an invocation.
Program: Ice.Lib.EpiClientLib.dll
Method: InvokeReflectedMethod

Client Stack Trace

at Ice.Lib.Framework.PCallReflector.InvokeReflectedMethod(MethodInfo Method, Object Object, Object MethodParams, String className, String assemblyName)
at Ice.Lib.Framework.PCallReflector.LaunchDotNet(String assemblyName, String className, Hashtable ctorList, String methodName, Hashtable methodList)

Inner Exception

Exception has been thrown by the target of an invocation.

Inner Stack Trace

at System.RuntimeMethodHandle.InvokeMethod(Object target, Object arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object parameters, Object arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture)
at Ice.Lib.Framework.PCallReflector.InvokeReflectedMethod(MethodInfo Method, Object Object, Object MethodParams, String className, String assemblyName)

Inner Exception

Object reference not set to an instance of an object.

Inner Stack Trace

at Erp.UI.App.TimeAndExpenseEntry.TimeExpenseForm.FormLoadFromApprovalEntry()
at Erp.UI.App.TimeAndExpenseEntry.TimeExpenseForm.LaunchForm(Object options)
at Ice.Lib.Framework.EpiBaseForm.ShowFormDialog(Object launchOptions)
at Ice.Lib.Framework.EpiBaseLaunch.LaunchForm(Object LaunchObject)
at Ice.Lib.App.Launch.LaunchForm(Object LaunchObject)

Are you sure you have a form named UDTimEnt? You should be able to find it in your Menu Maintenance.

Yup, and if I use the commented out field below (without the lfo), it launches (but without an empID).

image

Looks like it didn’t appreciate me leaving out a key field (laborDtlSeq) - Here’s my working code:

private void epiButtonC1_Click(object sender, System.EventArgs args)
	{
		// ** Place Event Handling Code Here **
	
	

		string yourEMP = "cconn"; //((Session)oTrans.Session).EmployeeID;
                Hashtable YourHashtable = new Hashtable();
                YourHashtable.Add("type","T");
                YourHashtable.Add("empID",yourEMP);
                YourHashtable.Add("laborDate",DateTime.Now);
	  	YourHashtable.Add("laborDtlSeq",0);
		YourHashtable.Add("mode","A");
                LaunchFormOptions lfo = new LaunchFormOptions();
	
                lfo.ValueIn = YourHashtable;

                ProcessCaller.LaunchForm(oTrans, "JCGO3002", lfo);
		//ProcessCaller.LaunchForm(this.oTrans, "UDTimEnt");
	
	}

Be sure to change your menu name back to UDTimEnt too

Thank @Chris_Conn! I’m getting closer. It’s now working; however, when it launches it seems to start a new LaborDtl record. I’m assuming it has something to do with the “mode,” “A” line or the “laborDtlSeq”, 0?

I’d like it to just launch with the current records. Like when you launch it normal in the standard Epicor.

Related question, how do you tell which Launch Args are needed and which are optional? I tried just leaving the Mode line out, but that didn’t work.

Thanks again for the help!

Change the mode to “U”

The problem here is that we are trying to force the system to do what we want, which is slightly different than it expects.

Here is what the code wants to do:

	base.LaunchForm(options);
	if (this.LaunchFormOpts != null && this.LaunchFormOpts.ValueIn != null)
	{
		object arg_27_0 = this.LaunchFormOpts.ValueIn;
		base.AutoSubscribe = false;
		if (this.LaunchFormOpts.PublisherKey.ToString().Length > 0)
		{
			this.trans.SubscribeToPublisher(this.LaunchFormOpts.PublisherKey);
		}
		this.FormLoadFromApprovalEntry();
		this.searchValues = null;
		return;
	}
	this.FormLoadFromDefaultEmpID();

So if we give some hashtable params like we are doing, it is doing that proc (.FormLoadFromApprovalEntry). What we really want to happen is that last line FormLoadFromDefaultEmpID(). However, it appears MES isn’t setting the value the form is looking for. Here is what happens:

private void FormLoadFromDefaultEmpID()
{
	string defaultEmpID = this.trans.GetDefaultEmpID();
	if (defaultEmpID != "" && this.trans.GetEmp(defaultEmpID))
	{
		this.trans.empCalendarInfo.SelectedDateRanges.Add(DateTime.Now, 0, true);
	}
}

I assume the issue is that emp is not linked to user or viceversa - that’s the only thing I can gather without debugging it.

1 Like

THANKS, the U worked.

It’s weird because each user ID is attached to an EmpID, and it works in the standard Epicor, I think it’s an MES oddity, but doesn’t matter now.

Thanks again for all your help on this.

1 Like

No problem, I’m stoked it worked. If it appears I know what I am doing, it’s just an optical illusion :wink:

2 Likes

What do you mean by import? When I am in the script Editor, it says " Error: CS0234 - line 19 (19) - The type or namespace name ‘Core’ does not exist in the namespace ‘Ice’ (are you missing an assembly reference?)"

image

image

image

Awesome, Thank you.
I have added that and now I am getting a new error, This is not for the TandE that was discussed, but I am using a Dashboard that I created. I get the below error.
Error: CS0103 - line 60 (92) - The name ‘oTrans’ does not exist in the current context
Error: CS0103 - line 71 (103) - The name ‘oTrans’ does not exist in the current context