0

I am setting the Default branch on the SOOrder using the Employees Default Branch:

enter image description here

using PX.Objects.IN.Matrix.Interfaces;
using System;
using PX.Common;
using PX.Data;
using PX.Objects.CS;
using PX.Objects.EP;
namespace PX.Objects.SO
{
    // Acuminator disable once PX1016 ExtensionDoesNotDeclareIsActiveMethod extension should be constantly active
    public class SOOrderEntry_Extension : PXGraphExtension<SOOrderEntry>
    {
        #region Event Handlers

        protected void SOLine_BranchID_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
        {
            try
            {
                var row = (SOLine)e.Row;
                if (row == null) return;

                EPEmployee CurEPEmployee = PXSelect<
                    EPEmployee, 
                    Where<EPEmployee.userID, Equal<Required<AccessInfo.userID>>>>
                    .Select(Base, Base.Accessinfo.UserID);

                BranchMaint.BranchBAccount CurBranchBAccount = PXSelect<
                    BranchMaint.BranchBAccount,
                    Where<BranchMaint.BranchBAccount.bAccountID,Equal<Required<EPEmployee.parentBAccountID>>>>
                    .Select(Base,CurEPEmployee.ParentBAccountID);

                e.NewValue = CurBranchBAccount.BranchBranchCD;

            }
            catch (Exception ex)
            {
                PXTrace.WriteError(ex);
            }

        }

        #endregion
  

When I use the same code to set the branch on Purchase Orders the BranchMaint.BranchBAccount is always null as if the POReceiptEntry_Extension doesn't have access to it?

using PX.Data;
using PX.Objects.EP;
using static PX.Objects.CS.BranchMaint;
using System;

namespace PX.Objects.PO
{
    // Acuminator disable once PX1016 ExtensionDoesNotDeclareIsActiveMethod extension should be constantly active
    public class POReceiptEntry_Extension : PXGraphExtension<POReceiptEntry>
    {
        #region Event Handlers

        protected void POReceiptLine_BranchID_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
        {

            try
            {
                var row = (POReceiptLine)e.Row;
                if (row == null) return;

                EPEmployee CurEPEmployee = PXSelect<
                    EPEmployee,
                    Where<EPEmployee.userID, Equal<Required<AccessInfo.userID>>>>
                    .Select(Base, Base.Accessinfo.UserID);

                BranchBAccount CurBranchBAccount = PXSelect<
                    BranchBAccount,
                    Where<BranchBAccount.bAccountID, Equal<Required<EPEmployee.parentBAccountID>>>>
                    .Select(Base, CurEPEmployee.ParentBAccountID);
         
                e.NewValue = CurBranchBAccount.BranchBranchCD;

            }
            catch (Exception ex)
            {
                PXTrace.WriteError(ex);
            }
        }


        #endregion
    }
}

Is there any way for me to access BranchMaint.BranchBAccount from POReceiptEntry_Extension

JvD
  • 473
  • 3
  • 18

1 Answers1

1

Try the below. Also consider though how you would want something like this to function in a PO Receipt, in most cases you are probably pulling from a Purcahse Order itself so the Branch will come from the PO not from your field defaulting extension.

         protected void POReceiptLine_BranchID_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
        {

            try
            {
                var row = (POReceiptLine)e.Row;
                if (row == null) return;

                EPEmployee CurEPEmployee = PXSelect<
                    EPEmployee,
                    Where<EPEmployee.userID, Equal<Required<AccessInfo.userID>>>>
                    .Select(Base, Base.Accessinfo.UserID);

                Branch CurBranchBAccount = PXSelect<
                    Branch,
                    Where<Branch.bAccountID, Equal<Required<EPEmployee.parentBAccountID>>>>
                    .Select(Base, CurEPEmployee.ParentBAccountID);

                e.NewValue = CurBranchBAccount.BranchCD;

            }
            catch (Exception ex)
            {
                PXTrace.WriteError(ex);
            }
        }