Automate Miscellaneous Valus in ApInvoice Entry

,

Dear Team,

I tried to automate the Miscellaneous values binding in APInvoiceEntry in Create the new receipt line. but i got the server error. The below BPM code and error messge. Kindly, help me.

string tmpPackNo = string.Empty;
int tmpPoNo = 0, tmpPoLne = 0, tmpVendorID = 0, tmpVendorNum = 0;
int tmpVenNo = 0;
string tmpRcvPackNo = string.Empty;
string tmpInvocieNo = string.Empty;
string tmpMiscCode = string.Empty;
decimal tmpMiscAmt = 0;

string tmpEmpty = string.Empty;
int tmpval = 0;
decimal tmpVal1 = 0;
bool tmpFalse= false;
string tmpGrp = string.Empty;
string purMiscCode = string.Empty;

InfoMessage.Publish(“1”);

var ttSelRctRow = (from s in ttAPSelectedRcptLines where (s.Company == Session.CompanyID) select s).FirstOrDefault();
//foreach(var ttSelRctRow in(from s in ttAPSelectedRcptLines where (s.Company == Session.CompanyID) select s))
if(ttSelRctRow != null)
{
tmpPackNo = Convert.ToString(ttSelRctRow[“PackSlip”]);
tmpInvocieNo = Convert.ToString(ttSelRctRow[“InvoiceNum”]);

var APInvHead = (from row in Db.APInvHed where row.Company == Session.CompanyID && row.InvoiceNum == tmpInvocieNo select row).FirstOrDefault();
if(APInvHead !=null)
{
tmpVenNo = Convert.ToInt32(APInvHead[“VendorNum”]);
tmpGrp = Convert.ToString(APInvHead[“GroupID”]);
}

InfoMessage.Publish(“2”);
InfoMessage.Publish("Vendor Num " + tmpVenNo.ToString());
InfoMessage.Publish("invoice Num " + tmpInvocieNo.ToString());

InfoMessage.Publish(“4”);
InfoMessage.Publish("Vendor Num " + tmpPackNo.ToString());

Erp.Contracts.APInvoiceSvcContract APInvcBO = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.APInvoiceSvcContract>(Db);
APInvcBO.GetByID(tmpVenNo,tmpInvocieNo);
Erp.Tablesets.APInvoiceTableset TblSet = new Erp.Tablesets.APInvoiceTableset();

/*foreach(var RcvMiscRow in(from Misc in Db.RcvMisc where (Misc.Company == Session.CompanyID && Misc.PackSlip == tmpPackNo) select Misc).ToList())
{
  tmpMiscCode = Convert.ToString(RcvMiscRow["MiscCode"]);
  tmpMiscAmt = Convert.ToDecimal(RcvMiscRow["DocActualAmt"]);      
}*/

//var RcvMiscRow = (from Misc in Db.RcvMisc where (Misc.Company == Session.CompanyID && Misc.PackSlip == tmpPackNo) select Misc).FirstOrDefault();
foreach(var RcvMiscRow in(from Misc in Db.RcvMisc where (Misc.Company == Session.CompanyID && Misc.PackSlip == tmpPackNo) select Misc))
//if(RcvMiscRow != null)
// if(tmpMiscCode != null && tmpMiscAmt > 0)
{
tmpMiscCode = Convert.ToString(RcvMiscRow[“MiscCode”]);
tmpMiscAmt = Convert.ToDecimal(RcvMiscRow[“DocActualAmt”]);

//CallContext.Current.ExceptionManager.AddBLException("Misc Code - "  +tmpMiscCode.ToString());
//CallContext.Current.ExceptionManager.AddBLException("Misc Amt - "  +tmpMiscAmt.ToString());
  
InfoMessage.Publish("Misc Code - "  + tmpMiscCode.ToString());

//var ttPurMiscRow = (from P in Db.PurMisc where (P.Company == Session.CompanyID && P.MiscCode == tmpMiscCode) select P).FirstOrDefault();
foreach(var ttPurMiscRow in(from P in Db.PurMisc where (P.Company == Session.CompanyID && P.MiscCode == tmpMiscCode) select P))
if(ttPurMiscRow != null)
{
  purMiscCode = Convert.ToString(ttPurMiscRow["MapChargeID_c"]); 
  
  InfoMessage.Publish("Group Name - " + tmpGrp.ToString());
  InfoMessage.Publish("Map Misc Code - "  + purMiscCode.ToString()); 
  InfoMessage.Publish("Misc Amt - " + tmpMiscAmt.ToString()); 
    
  APInvcBO.GetNewHdrCharge(ref TblSet,tmpVenNo,tmpInvocieNo,false);
    //APInvcBO.ChangeMiscCode("RFR1","APIHAPInvMsc",ref TblSet);
    //APInvcBO.ChangeMiscAmt(100,"APIHAPInvMsc",ref TblSet);
    
  APInvcBO.ChangeMiscCode(purMiscCode,"APIHAPInvMsc",ref TblSet);
  APInvcBO.ChangeMiscAmt(tmpMiscAmt,"APIHAPInvMsc",ref TblSet);
  InfoMessage.Publish("5");
    
  TblSet.APIHAPInvMsc[0].Company = Session.CompanyID;
  InfoMessage.Publish("6");
  TblSet.APIHAPInvMsc[0].GroupID = tmpGrp;
  TblSet.APIHAPInvMsc[0].VendorNum = tmpVenNo;
  TblSet.APIHAPInvMsc[0].InvoiceNum = tmpInvocieNo;
  TblSet.APIHAPInvMsc[0].InvoiceLine = 0;
  TblSet.APIHAPInvMsc[0].MiscCode = purMiscCode;
  TblSet.APIHAPInvMsc[0].MiscAmt = tmpMiscAmt;
  TblSet.APIHAPInvMsc[0].RowMod = "A";
    
  InfoMessage.Publish("7");
  
  
}
APInvcBO.UpdateMaster(ref TblSet,tmpGrp,"APIHAPInvMsc",false,false,false,false,out tmpVal1,out tmpFalse,out tmpEmpty,out tmpEmpty,out tmpEmpty,out tmpFalse,out tmpFalse,out tmpEmpty);
//break;

}
}

I received the following error

Error:

Server Side Exception

A server error occurred. Review the server event logs for details.

Exception caught in: Epicor.ServiceModel

Error Detail

Correlation ID: 308ed503-7981-4e91-930f-7a6e10bedb2e
Description: A server error occurred. Review the server event logs for details.
Program: Epicor.System.dll
Method: ProvideFault
Line Number: 33
Column Number: 17
Server Trace Stack: at Epicor.Hosting.Wcf.ErrorHandler.ProvideFault(Exception error, MessageVersion version, Message& fault) in C:_Releases\ICE\UD10.2.600.11FW\Source\Framework\Epicor.System\Hosting\Wcf\ErrorHandler.cs:line 33
at System.ServiceModel.Dispatcher.ErrorBehavior.ProvideFault(Exception e, FaultConverter faultConverter, ErrorHandlerFaultInfo& faultInfo)
at System.ServiceModel.Dispatcher.ErrorBehavior.ProvideMessageFaultCore(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage8(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.ProcessError(Exception e)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
at System.ServiceModel.Dispatcher.ChannelHandler.DispatchAndReleasePump(RequestContext request, Boolean cleanThread, OperationContext currentOperationContext)
at System.ServiceModel.Dispatcher.ChannelHandler.HandleRequest(RequestContext request, OperationContext currentOperationContext)
at System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult result)
at System.ServiceModel.Dispatcher.ChannelHandler.OnAsyncReceiveComplete(IAsyncResult result)
at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously)
at System.ServiceModel.Channels.SecurityChannelListener1.ReceiveItemAndVerifySecurityAsyncResult2.InnerTryReceiveCompletedCallback(IAsyncResult result)
at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously)
at System.ServiceModel.Channels.TransportDuplexSessionChannel.TryReceiveAsyncResult.OnReceive(IAsyncResult result)
at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously)
at System.ServiceModel.Channels.SynchronizedMessageSource.ReceiveAsyncResult.OnReceiveComplete(Object state)
at System.ServiceModel.Channels.SessionConnectionReader.OnAsyncReadComplete(Object state)
at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
at System.Net.Security.NegotiateStream.ProcessFrameBody(Int32 readBytes, Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.NegotiateStream.ReadCallback(AsyncProtocolRequest asyncRequest)
at System.Net.AsyncProtocolRequest.CompleteRequest(Int32 result)
at System.Net.FixedSizeReader.CheckCompletionBeforeNextRead(Int32 bytes)
at System.Net.FixedSizeReader.ReadCallback(IAsyncResult transportResult)
at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously)
at System.ServiceModel.Channels.ConnectionStream.IOAsyncResult.OnAsyncIOComplete(Object state)
at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(SocketAsyncEventArgs e)
at System.Net.Sockets.SocketAsyncEventArgs.FinishOperationSuccess(SocketError socketError, Int32 bytesTransferred, SocketFlags flags)
at System.Net.Sockets.SocketAsyncEventArgs.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

Client Stack Trace

at Epicor.ServiceModel.Channels.ImplBase`1.ShouldRethrowNonRetryableException(Exception ex, DataSet[] dataSets)
at Erp.Proxy.BO.APInvoiceImpl.InvoiceSelectedLines(APInvReceiptBillingDataSet ds, String& opLOCMsg)
at Erp.Adapters.APInvoiceAdapter.InvoiceSelectedLines(String& opLOCMsg)

@IsaiSelvan
If the PO has miscellaneous charges.
While booking the AP invoice, once the receipt line is created, user can retrieve the miscellaneous charges in the AP invoice, either in the header or line. This is standard functionality in Epicor.

Are you trying to do something different through BPM ?

thanks @prash172. The above BPM code used for automatically the miscellaneous charge codes are binding when we create a new Receipt line.