Creating an Employee from Person / Contact

Trying to add a button to create an employee from the Person / Contact form. I’m using this code:

private static void btnCreateEmp_Click(object sender, System.EventArgs args)
	{
		// ** Place Event Handling Code Here **
		DataRow currentRow = edvPerCon.CurrentDataRow;
		EmpBasicAdapter adapterEmp = new Erp.Adapters.EmpBasicAdapter(oTrans);	
    	adapterEmp.BOConnect();
		var dr = adapterEmp.EmpBasicData.EmpBasic.NewEmpBasicRow();
		dr.BeginEdit();
			dr["EmpID"] = currentRow["PerConID"].ToString();
			dr["Company"] = currentRow["Company"].ToString();
			dr["FirstName"] = currentRow["FirstName"].ToString();
			dr["MiddleInitial"] = currentRow["MiddleName"].ToString();
			dr["LastName"] = currentRow["LastName"].ToString();
			if (currentRow["Suffix"].ToString() != "") dr["LastName"] = dr["LastName"] + " " + currentRow["Suffix"].ToString();
			dr["EmpStatus"] = "A";
			dr["Profile_C"] = "";
			dr["ActPayRate_c"] = 0.00;
			dr["ExpenseCode"] = "NOCODE";
			dr["Shift"] = "001";
			dr["RowMod"] = "A";
		dr.EndEdit();
		adapterEmp.EmpBasicData.EmpBasic.AddEmpBasicRow(dr);
		adapterEmp.Update();		
	}

When I run it, I get the following error:

Application Error

Exception caught in: Epicor.ServiceModel

Error Detail 
============
Message: Object reference not set to an instance of an object.
Program: Epicor.ServiceModel.dll
Method: ShouldRethrowNonRetryableException

Client Stack Trace 
==================
   at Erp.Services.BO.EmpBasicSvc.EmpBasicBeforeUpdate() in C:\_Releases\ERP\UD10.1.500.46\Source\Server\Services\BO\EmpBasic\EmpBasic.cs:line 1864
   at Ice.Services.Trace.TablesetProfilingCollector.DoRowEventTrace(String tableName, String methodName, Int32 rowCount, Action action) in D:\_Releases\ICE\3.1.500.46\Source\Framework\Epicor.Ice\Services\TablesetProfilingCollector.cs:line 144
   at Ice.TablesetBound`3.CreateRow(IceDataContext dataContext, Int32 tableNum, IIceTable table, IceRow newTablesetRow, TablesetProfilingCollector parentTraceCollector) in D:\_Releases\ICE\3.1.500.46\Source\Framework\Epicor.Ice\Services\TablesetBound.cs:line 1016
   at Ice.TablesetBound`3.WriteTable(IceDataContext dataContext, Int32 tableIndex, IIceTable table, TablesetProfilingCollector parentTraceCollector) in D:\_Releases\ICE\3.1.500.46\Source\Framework\Epicor.Ice\Services\TablesetBound.cs:line 886
   at Ice.TablesetBound`3.InnerUpdate(IceDataContext dataContext, TFullTableset tableset) in D:\_Releases\ICE\3.1.500.46\Source\Framework\Epicor.Ice\Services\TablesetBound.cs:line 805
   at Erp.Services.BO.EmpBasicSvc.Update(EmpBasicTableset& ds) in C:\_Releases\ERP\UD10.1.500.46\Source\Server\Services\BO\EmpBasic\EmpBasic.Designer.cs:line 2299
   at Epicor.Customization.Bpm.MethodCustomizationBase2`3.RunDirectives(TParam parameters) in c:\_Releases\ICE\3.1.500\Current\Source\Server\Internal\Lib\Epicor.Customization.Bpm\MethodCustomizationBase2.cs:line 214
   at Epicor.Customization.Bpm.CustomizationBase2`3.Execute(TParam parameters) in c:\_Releases\ICE\3.1.500\Current\Source\Server\Internal\Lib\Epicor.Customization.Bpm\CustomizationBase2.cs:line 77
   at Epicor.Customization.Bpm.BO99C2A5AF5B754126A72844EB6A3CA4A6.EmpBasicSvcCustomization.Update(EmpBasicTableset& ds)
   at Erp.Services.BO.EmpBasicSvcFacade.Update(EmpBasicTableset& ds) in C:\_Releases\ERP\UD10.1.500.46\Source\Server\Services\BO\EmpBasic\EmpBasicSvcFacade.cs:line 904
   at SyncInvokeUpdate(Object , Object[] , Object[] )
   at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
   at Epicor.Hosting.OperationBoundInvoker.InnerInvoke(Object instance, Func`2 func) in D:\_Releases\ICE\3.1.500.46\Source\Framework\Epicor.System\Hosting\OperationBoundInvoker.cs:line 59
   at Epicor.Hosting.OperationBoundInvoker.Invoke(Object instance, Func`2 func) in D:\_Releases\ICE\3.1.500.46\Source\Framework\Epicor.System\Hosting\OperationBoundInvoker.cs:line 47
   at Epicor.Hosting.Wcf.EpiOperationInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) in D:\_Releases\ICE\3.1.500.46\Source\Framework\Epicor.System\Hosting\Wcf\EpiOperationInvoker.cs:line 23
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

   at Epicor.ServiceModel.Channels.ImplBase`1.ShouldRethrowNonRetryableException(Exception ex, DataSet[] dataSets)
   at Erp.Proxy.BO.EmpBasicImpl.Update(EmpBasicDataSet ds)
   at Erp.Adapters.EmpBasicAdapter.OnUpdate()
   at Ice.Lib.Framework.EpiBaseAdapter.Update()
   at Script.btnCreateEmp_Click(Object sender, EventArgs args)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at Infragistics.Win.Misc.UltraButtonBase.OnClick(EventArgs e)
   at Ice.Lib.Framework.EpiButton.OnClick(EventArgs e)
   at Infragistics.Win.Misc.UltraButton.OnMouseUp(MouseEventArgs e)
   at Ice.Lib.Framework.EpiButton.OnMouseUp(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

If I comment out the AddRow, it does not error (also doesn’t add the record)

It behaves almost like Adding the Row is then closing the Adapter. Am I missing something?

Not a direct answer.

It might be better to move this code to a BPM as using the BO Widgets would be a bit easier.

At least that way you can see the code, as I think there are few BO method calls missing.

Did you run a trace and grab all of the methods called when entering an Employee Manually?

EmpBasicAdapter adapterEmp = new Erp.Adapters.EmpBasicAdapter(oTrans);	
     	adapterEmp.BOConnect();

adapterEmp.GetNewEmpBasic();
var dr = adapterEmp.EmpBasicData.EmpBasic[0];

dr.BeginEdit();
	dr["EmpID"] = "poop";
	dr["Company"] = "PutYoursIn";
	dr["FirstName"] = "a";
	dr["MiddleInitial"] = "B";
	dr["LastName"] = "c";
	dr["EmpStatus"] = "A";
	dr["ExpenseCode"] = "0001";
	dr["Shift"] = 7;
dr.EndEdit();
adapterEmp.Update();		

That’ll fix you up.

I’d also follow @knash advice though and move it to a BPM.

1 Like

Thank you so much Kevin. I appreciate the help. This did it.

1 Like