I have a custom process that needs to happen at the time of an invoice being released. Being this process calls out to a web service I need to wrap that code in a PXLongOperation per an Acumatica best practice. if I wrap the PXLongOperation in a try/finally block things work fine relative to the UI but if I run an integration test that executed the action item calling the PXLongOperation I now get the "The previous operation has not been completed yet." error. where these passed fine before adding the long operation.
Thanks for your help
[PXOverride]
public IEnumerable Release(PXAdapter adapter, ReleaseDelegate baseMethod)
{
//IEnumerable returnValue = null;
try
{
ARInvoice invoice = Base.Document.Current;
CtpARInvoiceExt invoiceExt = PXCache<ARInvoice>.GetExtension<CtpARInvoiceExt>(invoice);
if (invoice.DocType == "CRM")
{
PXLongOperation.StartOperation(Base, () => { ProcessClickToPayCreditMemoInvoice(invoice, invoiceExt); });
}
return baseMethod(new PXAdapter(Base.CurrentDocument));
}
//todo: I did find that this is raising an error behind the scenes but if this is commented out
// everything works as expected.
// I have found that even if this gets commented out the the integration tests that are using
// The Contract Bases Soap API are failing indicating that the process has not completed.
//catch (Exception e)
//{
// //todo: this is throwing an exception with message: The previous operation has not been completed yet.
// throw new PXException(e,CtpMessages.ClickToPayReleaseOverrideFailed, e.Message);
//}
finally
{
//... exit logic
}
}
The call that fails with the Contract Soap API is
InvokeResult invokeResult = SoapClient.Invoke(invoice, new ReleaseInvoice());