Can not delete an invoice in a group

Epicor will not let me delete an invoice in a group. Below is the error I get when I try to delete it. Any assistance would be appreciated.

Application Error

Exception caught in: Epicor.ServiceModel

Error Detail

============

Message: An error occurred while updating the entries. See the inner exception for details.

Inner Exception Message: Violation of PRIMARY KEY constraint ‘PK_TaxSvcMessages’. Cannot insert duplicate key in object ‘Erp.TaxSvcMessages’. The duplicate key value is (HCI, I-1030167, 0).

The statement has been terminated.

Program: Epicor.ServiceModel.dll

Method: ShouldRethrowNonRetryableException

Client Stack Trace

==================

at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)

at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)

at Ice.IceDataContext.SaveChanges(SaveOptions options) in C:_Releases\ICE\3.1.500.7\Source\Framework\Epicor.System\Data\IceDataContext.cs:line 328

at Ice.IceDataContext.Validate[TLinqRow](TLinqRow row) in C:_Releases\ICE\3.1.500.7\Source\Framework\Epicor.System\Data\IceDataContext.cs:line 295

at Erp.Internal.Lib.ProcessTaxes.CancelTax(List`1 ttTxSvcHeadRows, Boolean& opCommFailure, String& opErrMessage) in C:_Releases\ERP\UD10.1.500.7\Source\Server\Internal\Lib\ProcessTaxes\ProcessTaxes\ProcessTaxes.i.cs:line 11101

at Erp.Internal.Lib.ProcessTaxes.CalcTaxes(Int32 ipQuoteNum, Int32 ipOrderNum, Int32 ipInvoiceNum, String ipAPInvKey, String ipCashHeadNum, Int32 ipPayHeadNum, Int32 ipShipPackNum, String ipEmpID, Int32 ipEmpExpenseNum, Int32 ipPoNum, Boolean whInclRgn, Boolean& opCommFailure, String& opMessage, Boolean& opTCStatus, List1& ttTxSvcHeadRows, List1& ttTxSvcDetailRows) in C:_Releases\ERP\UD10.1.500.7\Source\Server\Internal\Lib\ProcessTaxes\ProcessTaxes\ProcessTaxes.i.cs:line 7869

at Erp.Services.BO.ARInvoiceSvc.SetReadyToCalcEx(String ipGroupID, Int32 ipInvoiceNum, Boolean ipCalcAll, Boolean ipCalledFromUI, ARInvoiceTableset& ds) in C:_Releases\ERP\UD10.1.500.7\Source\Server\Services\BO\ARInvoice\ARInvoice.cs:line 38997

at Erp.Services.BO.ARInvoiceSvc.InvcDtlAfterUpdate() in C:_Releases\ERP\UD10.1.500.7\Source\Server\Services\BO\ARInvoice\ARInvoice.cs:line 0

at Ice.Services.Trace.TablesetProfilingCollector.DoRowEventTrace(String tableName, String methodName, Int32 rowCount, Action action) in C:_Releases\ICE\3.1.500.7\Source\Framework\Epicor.Ice\Services\TablesetProfilingCollector.cs:line 146

at Ice.TablesetBound`3.UpdateRow(IceDataContext dataContext, Int32 tableNum, IIceTable table, IceRow updatedRow, IceRow originalRow, TablesetProfilingCollector parentTraceCollector) in C:_Releases\ICE\3.1.500.7\Source\Framework\Epicor.Ice\Services\TablesetBound.cs:line 1186

at Ice.TablesetBound`3.WriteTable(IceDataContext dataContext, Int32 tableIndex, IIceTable table, TablesetProfilingCollector parentTraceCollector) in C:_Releases\ICE\3.1.500.7\Source\Framework\Epicor.Ice\Services\TablesetBound.cs:line 895

at Ice.TablesetBound`3.InnerUpdate(IceDataContext dataContext, TFullTableset tableset) in C:_Releases\ICE\3.1.500.7\Source\Framework\Epicor.Ice\Services\TablesetBound.cs:line 797

at Erp.Services.BO.ARInvoiceSvc.Update(ARInvoiceTableset& ds) in C:_Releases\ERP\UD10.1.500.7\Source\Server\Services\BO\ARInvoice\ARInvoice.Designer.cs:line 3909

at Erp.Services.BO.ARInvoiceSvc.UpdateMaster(ARInvoiceTableset& ds, String cGroupID, String cTableName, Boolean runCheckAmortSched, Boolean runChkLtrOfCredit, Boolean& genAmortSched, Boolean lRASchedExists, Int32 ipInvoiceNum, Int32 ipInvoiceLine, String cARLOCID, Boolean suppressUserPrompts, Decimal dTotalCharges, Boolean lGetDefaultAccount, Decimal& grpTotalInvAmt, String& opGenMessage, String& opLtrCrdMsg, Boolean& lUpdateRan) in C:_Releases\ERP\UD10.1.500.7\Source\Server\Services\BO\ARInvoice\ARInvoice.cs:line 40896

at Erp.Services.BO.ARInvoiceSvcFacade.UpdateMaster(ARInvoiceTableset& ds, String cGroupID, String cTableName, Boolean runCheckAmortSched, Boolean runChkLtrOfCredit, Boolean& genAmortSched, Boolean lRASchedExists, Int32 ipInvoiceNum, Int32 ipInvoiceLine, String cARLOCID, Boolean suppressUserPrompts, Decimal dTotalCharges, Boolean lGetDefaultAccount, Decimal& grpTotalInvAmt, String& opGenMessage, String& opLtrCrdMsg, Boolean& lUpdateRan) in C:_Releases\ERP\UD10.1.500.7\Source\Server\Services\BO\ARInvoice\ARInvoiceSvcFacade.cs:line 3007

at SyncInvokeUpdateMaster(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 C:_Releases\ICE\3.1.500.7\Source\Framework\Epicor.System\Hosting\OperationBoundInvoker.cs:line 59

at Epicor.Hosting.OperationBoundInvoker.Invoke(Object instance, Func`2 func) in C:_Releases\ICE\3.1.500.7\Source\Framework\Epicor.System\Hosting\OperationBoundInvoker.cs:line 47

at Epicor.Hosting.Wcf.EpiOperationInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) in C:_Releases\ICE\3.1.500.7\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)

Inner Trace:

Violation of PRIMARY KEY constraint ‘PK_TaxSvcMessages’. Cannot insert duplicate key in object ‘Erp.TaxSvcMessages’. The duplicate key value is (HCI, I-1030167, 0).

The statement has been terminated.

: at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)

at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)

at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)

at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()

at System.Data.SqlClient.SqlDataReader.get_MetaData()

at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)

at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)

at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)

at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)

at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)

at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)

at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary2 identifierValues, List1 generatedValues)

at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)

at Epicor.ServiceModel.Channels.ImplBase`1.ShouldRethrowNonRetryableException(Exception ex, DataSet[] dataSets)

at Erp.Proxy.BO.ARInvoiceImpl.UpdateMaster(ARInvoiceDataSet ds, String cGroupID, String cTableName, Boolean runCheckAmortSched, Boolean runChkLtrOfCredit, Boolean& genAmortSched, Boolean lRASchedExists, Int32 ipInvoiceNum, Int32 ipInvoiceLine, String cARLOCID, Boolean suppressUserPrompts, Decimal dTotalCharges, Boolean lGetDefaultAccount, Decimal& grpTotalInvAmt, String& opGenMessage, String& opLtrCrdMsg, Boolean& lUpdateRan)

at Erp.Adapters.ARInvoiceAdapter.UpdateMaster(String cGroupID, String cTableName, Boolean runCheckAmortSched, Boolean runChkLtrOfCredit, Boolean& genAmortSched, Boolean lRASchedExists, Int32 ipInvoiceNum, Int32 ipInvoiceLine, String cARLOCID, Boolean suppressUserPrompts, Decimal dTotalCharges, Boolean lGetDefaultAccount, Decimal& grpTotalInvAmt, String& opGenMessage, String& opLtrCrdMsg, Boolean& lUpdateRan)

at Erp.Adapters.ARInvoiceAdapter.UpdateMasterUsingPasteInsert(String cGroupID, String cTableName, Boolean runCheckAmortSched, Boolean runChkLtrOfCredit, Boolean& genAmortSched, Boolean lRASchedExists, Int32 ipInvoiceNum, Int32 ipInvoiceLine, String cARLOCID, Boolean suppressUserPrompts, Decimal dTotalCharges, Boolean lGetDefaultAccount, Decimal& grpTotalInvAmt, String& opGenMessage, String& opLtrCrdMsg, Boolean& lUpdateRan, String pasteInsertColumnsToValidate)

at Erp.UI.App.ARInvoiceEntry.Transaction.Update(Boolean refreshGroup)

Inner Exception

===============

Violation of PRIMARY KEY constraint ‘PK_TaxSvcMessages’. Cannot insert duplicate key in object ‘Erp.TaxSvcMessages’. The duplicate key value is (HCI, I-1030167, 0).

The statement has been terminated.

I recall having this exact problem. Has to do with tax calc existing for an invoice. Check the Summary tab for the invoice, and see if the lines total plus the tax equals the invoice total.

Here’s what I got from Epicor support:

If you are using an Epicor version more recent than version 10.1.300, I believe the error message can be resolved by deleting the offending record from the TaxSvcMessages table directly at SQL. As an Epicor employee I cannot officially advocate data record deletions directly at SQL but I mention that possible solution here because I recently worked with another customer who resolved the error in that manner; we were unable to find another way to proceed.

1 Like

Here’s what I ended up doing…

Instead of outright deleting the record (which there is no “undo”), I instead UPDATEd it, changing the Sequence from 0 to 10 (as this was easy to “undo” should something go wrong)

After that change, I was able to delete the Invoice and the AR Group.

1 Like

Did you update it using SQL or something else?

My lawyer advises me to “not remember” :wink:

But the fact that “UPDATE” is a SQL command and and it was written as such in my post …

I opened a support case to see if they made a datafix since this post in 2018…

Hopefully they have.

I posted a similar topic in 2017 (was probably the same incident). In there I mention

“unofficial” recommendations by Epicor Support

That wouldn’t have been the first (nor last) time that epicor support suggest I do something via SQL.

1 Like

Yes I have also been consulted to do so in certain cases.

I prefer a datafix from them so that it isn’t me directly updating the row.

2 Likes

They do have a datafix now to delete the taxsvcmessage.

2 Likes

Just to give a bit more information, TaxSvcMessages it stores informational messages received by Avalara Tax Connect.

Although no idea why it throws an error, it should be adding the records incrementing the sequence.

Just make sure that whatever tax is on the invoice is actually cancelled/deleted on the avalara side.

1 Like

Good point Jonathan- we reconcile our sales with what avalara is reporting so this invoice should show up if it is still remaining on avalara’s side.