技术咨询: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
_isSavingflag prevents the save action from re-triggering theFieldUpdatedevent 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.ClosedwithSOOrderStatus.Completedif that's the appropriate status for your business process. - The
PXRedirectRequiredExceptionwithTarget = Selfwill automatically close the open document window once all actions are done. - The
try/finallyblock ensures the flag gets reset even if an error occurs, preventing future event misfires.
内容的提问来源于stack exchange,提问作者srinivas k
相关产品推荐
相关产品推荐

