PXAction seemingly does nothing

2019-07-11 04:12发布

问题:

I am doing customization in Sales Order and I want to customize the action Cancel Order. I reflected the code but could only find this:

    public PXAction<SOOrder> cancelled;
    [PXUIField(Visible = false)]
    [PXButton(ImageKey = PX.Web.UI.Sprite.Main.DataEntryF)]
    protected virtual IEnumerable Cancelled(PXAdapter adapter)
    {
        return adapter.Get();
    }

Is it the right function to customize?

回答1:

It's a pretty good question because it involves more than just the business logic layer.

SOOrderEntry is a pretty powerful and complicated page that must handle multiple states. To do so, Acumatica Framework has an Automation Module that allows to set different values depending of the current state. When you click on Cancel Order, the framework triggers a state change defined in the page Automation Definitions (SM205010) and Automation Steps (SM205000). Look at the definition of the action Cancel Order below.

You can see that on clicking the button, some field are changed. Please note that the field Cancelled is set to True. The field Cancelled is a bound field of SOOrder with the following definition:

    #region Cancelled

    public abstract class cancelled : PX.Data.IBqlField
    {
    }
    protected Boolean? _Cancelled;
    [PXDBBool()]
    [PXDefault(false)]
    [PXUIField(DisplayName = "Canceled")]
    public virtual Boolean? Cancelled
    {
        get
        {
            return this._Cancelled;
        }
        set
        {
            this._Cancelled = value;
        }
    }
    #endregion

Now that we understand that a Field has been changed, we can look for event handlers that would handle this change. There is currently an event handler (FieldVerifying) that would ensure the order can be canceled before doing so. If you want to extend the validation logic you can customize this handler:

protected virtual void SOOrder_Cancelled_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)

If you'd prefer to add an event that would occur if the cancelation succeeded, you can create a new event handler (FieldUpdated):

protected virtual void SOOrder_Cancelled_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)

The code you found is only a placeholder to create a button and allow the framework to trigger the automation step when you press it.