You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

技术咨询:SOLine-Inventory字段更新事件中能否保存并关闭Sales Order单据

Great questions! Let's break down each requirement with actionable steps tailored for Acumatica development:

1. Saving the Sales Order in the SOLine.Inventory Field Updated Event

Absolutely, you can save the Sales Order from the SOLine.Inventory field updated event—you just need to be careful to avoid infinite loop triggers (since saving the order might re-fire field update events). Here's a clean implementation:

public class SOOrderEntryExtension : PXGraphExtension<SOOrderEntry>
{
    private bool _isSaving = false;

    protected void _(Events.FieldUpdated<SOLine, SOLine.inventoryID> e)
    {
        if (e.Row == null || _isSaving) return;

        try
        {
            _isSaving = true;
            // Save the current Sales Order using the standard workflow
            Base.Actions.Save.Run();
        }
        finally
        {
            _isSaving = false;
        }
    }
}
  • The _isSaving flag prevents the save action from re-triggering the FieldUpdated event repeatedly.
  • Using Base.Actions.Save.Run() ensures you leverage Acumatica's built-in validation, audit trails, and core business logic instead of manual database writes.
2. Closing the Sales Order When Inventory is Selected

To close the Sales Order when an Inventory item is selected, you'll need to update the order status, save changes, and then close the document window. Here's the extended implementation:

public class SOOrderEntryExtension : PXGraphExtension<SOOrderEntry>
{
    private bool _isProcessing = false;

    protected void _(Events.FieldUpdated<SOLine, SOLine.inventoryID> e)
    {
        if (e.Row == null || _isProcessing || e.NewValue == null) return;

        try
        {
            _isProcessing = true;
            SOOrder currentOrder = Base.Document.Current;
            if (currentOrder == null) return;

            // Update the order status to Closed (adjust to Completed if needed for your workflow)
            currentOrder.Status = SOOrderStatus.Closed;
            Base.Document.Update(currentOrder);

            // Save the updated order
            Base.Actions.Save.Run();

            // Trigger the standard Close action (optional, if your business rules require it)
            Base.Actions["Close"].Run();

            // Close the current document window in the UI
            throw new PXRedirectRequiredException(currentOrder, true, "Order Closed")
            {
                Mode = PXBaseRedirectException.WindowMode.NewWindow,
                Target = PXBaseRedirectException.WindowTarget.Self
            };
        }
        finally
        {
            _isProcessing = false;
        }
    }
}

Key Notes:

  • Swap SOOrderStatus.Closed with SOOrderStatus.Completed if that's the appropriate status for your business process.
  • The PXRedirectRequiredException with Target = Self will automatically close the open document window once all actions are done.
  • The try/finally block ensures the flag gets reset even if an error occurs, preventing future event misfires.

内容的提问来源于stack exchange,提问作者srinivas k

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 07:48:59