以编程方式更改当前分支

时间:2017-06-22 09:35:47

标签: acumatica

是否可以使用代码(AEF)在运行时更改分支?你怎么能在运行时这样做?假设我有一个自定义操作,点击后我想用代码更改公司,我该怎么做?

1 个答案:

答案 0 :(得分:1)

以下是可以通过编程方式更改当前分支的代码。

using PX.Common;
using PX.Data;
using PX.Objects.CS;
using System.Collections;
using System.Web;

namespace AccessInfoChange
{
    public class BranchMaintExtension : PXGraphExtension<BranchMaint>
    {
        public PXAction<BranchMaint.BranchBAccount> changeBranch;
        [PXUIField(DisplayName = "Change Branch")]
        [PXButton]
        public virtual IEnumerable ChangeBranch(PXAdapter adapter)
        {
                int branchObj = 5; //BranchID of Branch you would like to switch to
                PXContext.SetBranchID(branchObj);
                HttpCookie branchCooky = HttpContext.Current.Response.Cookies["UserBranch"];
                if (branchCooky == null)
                    HttpContext.Current.Response.Cookies.Add(new HttpCookie("UserBranch", "MAIN"));//BranchCD of Branch to switch
                else branchCooky.Value = branchObj.ToString();//String of IntegerID for BranchID to switch
            return adapter.Get();
        }
    }
}