Unfortunately from this code, I can’t say what the exact problem is, but I can suggest some changes which will help to avoid errors like this.
From this code, I saw you have a graph MixPaymentsEntry created for the MixPayments record. I hope this graph can be used for data manipulation in the MixPayments table.
- It is not necessary to use PXTransactionScope if the code uses only DB direct operation. In this code, you can just remove the PXTransactionScope.
- If the MixPayments records update depends on the Invoice Release process the best practice is to override the ReleaseInvoiceProc method and write your code before or after calling base method.
public delegate void ReleaseInvoiceProcDelegate(List<ARRegister> list, bool isMassProcess);
[PXOverride]
public void ReleaseInvoiceProc(List<ARRegister> list, bool isMassProcess, ReleaseInvoiceProcDelegate releaseInvoiceProc)
{
using (PXTransactionScope scope = new PXTransactionScope())
{
releaseInvoiceProc(list, isMassProcess);
scope.Complete();
}
}
You can write code without direct database updates, as @jinin pointed out above.
For example something like this:
public virtual void UpdateMixPayments(List<ARRegister> list)
{
foreach (ARRegister arregister in list)
{
ARInvoice invoice = ARInvoice.PK.Find(this.Base, arregister.DocType, arregister.RefNbr);
ARTran invLine = ARTran.FK.Invoice.SelectChildren(Base, invoice).FirstOrDefault();
if (invLine != null)
{
var mixPayments = Pay.Select(invLine.SOOrderNbr, invLine.SOOrderType);
MixPaymentsEntry mixPaymentsGraph = PXGraph.CreateInstance<MixPaymentsEntry>();
foreach (MixPayments mix in mixPayments)
{
mixPaymentsGraph.Clear();
if (mix.RefNbr is null || mix.DocType is null || mix.RefNbr == " <NEW>")
{
mixPaymentsGraph.MixPayments.Current = mix;
mixPaymentsGraph.MixPayments.Current.DocType = invoice.DocType;
mixPaymentsGraph.MixPayments.Current.RefNbr = invoice.RefNbr;
mixPaymentsGraph.MixPayments.Update(mixPaymentsGraph.MixPayments.Current);
mixPaymentsGraph.Save.Press();
}
}
}
}
}
Of course, the code written inside of second foreach loop depends on which type graph is MixPaymentsEntry. If it is the ListView the calling Clear() and Save action can be out of the foreach.
Then call this method during the process where you want to update records