I have a situation, where I need to add a Misc (row in InvMisc) charge to an AR Invoice. Method directive works fine if an invoice is created through UI!
But, we have several customers who are auto-invoice enabled. I have tried adding Data-Directive to InvcHead (once posted = true) and tried calling STANDARD directive to create Misc record, but this failed as the invoice already posted. I am running out of options. Is it safe to INSERT row into InvcMisc directly inside In-Trasaction data directive? If so, how can I do this?
Query failed to run
System.Data.Entity.Core.EntityException: The underlying provider failed on EnlistTransaction.
—> System.Transactions.TransactionException: The operation is not valid for the state of the transaction.
at System.Transactions.TransactionState.EnlistPromotableSinglePhase(InternalTransaction tx, IPromotableSinglePhaseNotification promotableSinglePhaseNotification, Transaction atomicTransaction, Guid promoterType)
at System.Transactions.Transaction.EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification promotableSinglePhaseNotification, Guid promoterType)
at System.Transactions.Transaction.EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification promotableSinglePhaseNotification)
at System.Data.SqlClient.SqlInternalConnection.EnlistNonNull(Transaction tx)
at System.Data.SqlClient.SqlInternalConnection.EnlistTransaction(Transaction transaction)
at System.Data.SqlClient.SqlConnection.EnlistTransaction(Transaction transaction)
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action2 operation, TInterceptionContext interceptionContext, Action3 executing, Action3 executed)
at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.EnlistTransaction(DbConnection connection, EnlistTransactionInterceptionContext interceptionContext)
at System.Data.Entity.Core.EntityClient.EntityConnection.EnlistTransaction(Transaction transaction)
— End of inner exception stack trace —
at System.Data.Entity.Core.EntityClient.EntityConnection.EnlistTransaction(Transaction transaction)
at System.Data.Entity.Core.Objects.ObjectContext.EnsureContextIsEnlistedInCurrentTransaction[T](Transaction currentTransaction, Func1 openConnection, T defaultValue) at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection(Boolean shouldMonitorTransactions) at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
at System.Data.Entity.Core.Objects.ObjectQuery1.<>c__DisplayClass41_0.<GetResults>b__0() at System.Data.Entity.Core.Objects.ObjectQuery1.<System.Collections.Generic.IEnumerable.GetEnumerator>b__31_0()
at System.Data.Entity.Internal.LazyEnumerator1.MoveNext() at System.Linq.Enumerable.TryGetSingle[TSource](IEnumerable1 source, Boolean& found)
at System.Linq.Enumerable.Single[TSource](IEnumerable1 source) at System.Data.Entity.Core.Objects.CompiledQuery.ExecuteQuery[TResult](ObjectContext context, Object[] parameterValues) at Epicor.Data.DBExpressionCompiler.GetResult[TDataContext,TQuery,TResult](Func3 executeQuery, Cache cacheSetting, TDataContext dataContext, TQuery query) in C:_releases\ICE\ICE4.2.200.19\Source\Server\Framework\Epicor.System\Data\DBExpressionCompiler.cs:line 446
at Epicor.Data.DBExpressionCompiler.InvokeSingle[TDataContext,TQuery,TResult](Expression expression, Cache currentCacheSetting, Boolean cacheQuery, TDataContext dataContext, Func2 getDataCacheKey, Func2 compileQuery, Func`3 executeQuery) in C:_releases\ICE\ICE4.2.200.19\Source\Server\Framework\Epicor.System\Data\DBExpressionCompiler.cs:line 307
(context, Company_ex, ABTUID_ex) => context.RvJrnTr.Where(row => ((row.Company == Company_ex) AndAlso (row.ABTUID == ABTUID_ex))).Any()
Thank you, @Hally. I did add the Misc charges to the shipment and it works well. Only observation I have is that, in the Shipment, I can only add Misc charges to the Shipment Header. But, when the Invoice is created, it applies to the line level and to the line 1. This to me is inconsistent as I wanted to add the Misc charges to the Line level.