如何将自定义业务逻辑添加到 Acumatica 框架的操作中?

How to add custom business logic to Acumatica framework's Actions?

我向 SOShipment 添加了一个自定义字段,我想在订单输入或通过处理订单屏幕调用 CreateShipment 操作时设置它的值。我该怎么做?

为 SOOrderEntry 创建图形扩展并添加如下操作方法:

using PX.Data;
using System.Collections;

namespace PX.Objects.SO
{

    public class SOOrderEntry_Extension : PXGraphExtension<SOOrderEntry>
    {
        public PXAction<SOOrder> action;
        [PXUIField(DisplayName = "Actions", MapEnableRights = PXCacheRights.Select)]
        [PXButton]
        protected virtual IEnumerable Action(PXAdapter adapter,
            [PXInt]
            [PXIntList(new int[] { 1, 2, 3, 4, 5 }, new string[] { "Create Shipment", "Apply Assignment Rules", "Create Invoice", "Post Invoice to IN", "Create Purchase Order" })]
            int? actionID,
            [PXDate]
            DateTime? shipDate,
            [PXSelector(typeof(INSite.siteCD))]         
            string siteCD,
            [SOOperation.List]
            string operation,
            [PXString()]
            string ActionName)
        {
            //actionID = 1 means the CreateShipment action was the one invoked
            if (actionID == 1)
            {
                PXGraph.InstanceCreated.AddHandler<SOShipmentEntry>((graph) =>
                {
                    graph.RowInserting.AddHandler<SOShipment>((sender, e) =>
                    {
                        //Custom logic goes here
                        var shipment = (SOShipment)e.Row;
                        var shipmentExt = PXCache<SOShipment>.GetExtension<SOShipmentExt>(shipment);
                        if (Base.Document.Current != null && shipmentExt != null)
                        {
                            shipmentExt.UsrPriority = Base.Document.Current.Priority;
                        }
                    });
                });
            }

            //calls the basic action that was invoked
            return Base.action.Press(adapter);
        }
    }
}

当 SOOrderEntry 的任何操作为 运行 时(即使通过处理订单屏幕),也会调用此方法。我们验证该操作确实是带有 actionID == 1 的 CreateShipment,并为 SOShipmentEntry 图创建和 SOShipment RowInserting 添加事件处理程序。我们的自定义逻辑添加到 RowInserting 事件中。