如何在Acumatica框架的操作中添加自定义业务逻辑? [英] How to add custom business logic to Acumatica framework's Actions?

查看:43
本文介绍了如何在Acumatica框架的操作中添加自定义业务逻辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SOShipment中添加了一个自定义字段,我想在订单输入或流程订单屏幕上调用CreateShipment操作时设置其值。我该怎么做?

I added a custom field to SOShipment and I want to set its value when the CreateShipment action is invoked on Order Entry or through Process Orders screens. How do I do that ?

推荐答案

为SOOrderEntry创建图形扩展并添加如下所示的Action方法:

Create a graph extension for SOOrderEntry and add an Action method like this :

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事件中。

When any of SOOrderEntry's actions is run (even through the Process Orders screen), this method is invoked. We verify that the action really is CreateShipment with the actionID == 1 and add events handler for SOShipmentEntry graph creation and SOShipment RowInserting. Our custom logic is added inside the RowInserting event.

这篇关于如何在Acumatica框架的操作中添加自定义业务逻辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆