正在获取“先前的操作尚未完成”。如果在通过Contract Soap API调用的操作中使用PXLongOperation,则为异常

时间:2019-03-29 21:59:10

标签: acumatica

我有一个自定义流程,需要在下达发票时进行。通过此过程可以调用Web服务,我需要按照Acumatica最佳实践将该代码包装在PXLongOperation中。如果我将PXLongOperation包装在try / finally块中,则相对于UI来说一切正常,但是如果我运行一个集成测试,该操作执行了调用PXLongOperation的操作项,则我会得到“先前的操作尚未完成”。错误。在添加长操作之前,这些命令通过的情况很好。

感谢您的帮助

        [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 
        }

    }

使用Contract Soap API失败的调用是

InvokeResult invokeResult = SoapClient.Invoke(invoice, new ReleaseInvoice());

1 个答案:

答案 0 :(得分:1)

此设计模式可用于迫使您的方法等待较长的操作完成。

TimeSpan timespan;
Exception ex;
while (PXLongOperation.GetStatus(docgraph.UID, out timespan, out ex) == PXLongRunStatus.InProcess)
{ }

    // should be finished now
    // return baseMethod...