自定义逻辑在基本操作之前不会触发" APPROVE"

时间:2016-09-01 02:20:55

标签: acumatica

当我在申请单屏幕上的APPROVE之前执行自定义逻辑时,似乎逻辑被触发。我的代码如下。

public PXAction<RQRequisition> action;
[PXUIField(DisplayName = "Actions")]
[PXButton]
protected virtual IEnumerable Action(PXAdapter adapter,
    [PXInt][PXIntList(new int[] { 1, 2 }, new string[] { "Approve", "Reject" })] int? actionID,
    [PXBool]bool refresh,
    [PXString]string actionName)
{
    if (adapter.Menu == "Approve")
    {
        SIApprovalInfo.updateNextApprover(this.Base);

    }
    return Base.action.Press(adapter);
}

我尝试了此操作而未调用 return Base.action.Press(adapter);

示例代码:

public PXAction<RQRequisition> action;
[PXUIField(DisplayName = "Actions")]
[PXButton]
protected virtual IEnumerable Action(PXAdapter adapter,
    [PXInt][PXIntList(new int[] { 1, 2 }, new string[] { "Approve", "Reject" })]int? actionID,
    [PXBool]bool refresh,
    [PXString]string actionName)
{
    if (adapter.Menu == "Approve")
    {
        SIApprovalInfo.updateNextApprover(this.Base);

    }
    return adapter.Get();
}

该文件仍以某种方式获得批准。那么这个批准究竟在哪里被触发?如何在该操作之前添加自定义逻辑?

1 个答案:

答案 0 :(得分:0)

我建议一种解决方法,即创建自己的操作,将其添加到菜单中,并根据您的业务逻辑调用Approval。以下是您可以使用的基本代码段:

using PX.Data;
using System.Collections;

namespace PX.Objects.RQ
{
    public class RQRequisitionEntry_Extension : PXGraphExtension<RQRequisitionEntry>
    {
        public override void Initialize()
        {
            Base.action.AddMenuAction(CustomApprove);
            CustomApprove.SetEnabled(true);
        }

        public PXAction<RQRequisition> CustomApprove;
        [PXButton]
        [PXUIField(DisplayName = "Custom Approve")]
        protected virtual IEnumerable customApprove(PXAdapter adapter)
        {
            PXCache cache = Base.Caches[typeof(RQRequisition)];
            var requisition = Base.Document.Current;
            if (Base.Approval.Approve(requisition))
            {
                requisition.Approved = true;
                yield return Base.Document.Update(requisition); ;
            }
            else
            {
                throw new PXInvalidOperationException(PXLocalizer.Localize("Approval failed"));
            }
        }
    }
}