Skip to main content
Solved

Auto-Fill Restrict Visibility

  • June 11, 2024
  • 1 reply
  • 76 views

Forum|alt.badge.img+2

We have two companies, soon to be three, setup on Acumatica and they do not share customers at all. We have been using the “Restrict Visibility” field to make it so that employees can only access customers that are a part of their company. Unfortunately, people forget to fill in this field all the time, leading us to have to go through manually figuring out what company they belong to every now and then. I looked into trying to auto-fill this field using customer classes, but the customer classes are shared between companies, so that’s not an option. I decided to turn to coding and try to use PXDefault to pull the branch/company from what the user is signed into, but I can’t get it to work and it just keeps throwing the following error. If anyone could give me a hand, that would be great.

The multi-part identifier "Customer.COrgBAccountID" could not be bound.

 

Here is my code

namespace PX.Objects.AR
{
      [PXNonInstantiatedExtension]
  public class AR_Customer_ExistingColumn : PXCacheExtension<PX.Objects.AR.Customer>
  {
        #region COrgBAccountID  
        [PXDefault(typeof(Search2<Organization.bAccountID, LeftJoin<Branch, On<Branch.organizationID, Equal<Organization.organizationID>, And<Branch.branchID, Equal<Current<AccessInfo.branchID>>>>>>))]
      public int? COrgBAccountID { get; set; }
      #endregion
  }
}

 

Best answer by DrewNisley

Just decided to revisit this today and found a solution. I added the code below to create a FieldDefaulting event and it works as it should.

using PX.Data;
using PX.Objects.GL;

namespace PX.Objects.AR
{
    // Acuminator disable once PX1016 ExtensionDoesNotDeclareIsActiveMethod extension should be constantly active
    public class CustomerMaint_Extension : PXGraphExtension<PX.Objects.AR.CustomerMaint>
    {
        #region Event Handlers
        protected void _(Events.FieldDefaulting<Customer, Customer.cOrgBAccountID> e)
        {
            Customer row = e.Row;
            Branch company = PXSelect<Branch, Where<Branch.branchID, Equal<Current<AccessInfo.branchID>>>>.Select(Base);

            int branch = company.BAccountID.GetValueOrDefault();
            e.Cache.SetValueExt<Customer.cOrgBAccountID>(row, branch);
        }
    #endregion
  }
}

 

View original
Did this topic help you find an answer to your question?

1 reply

Forum|alt.badge.img+2
  • Author
  • Semi-Pro III
  • 64 replies
  • Answer
  • August 2, 2024

Just decided to revisit this today and found a solution. I added the code below to create a FieldDefaulting event and it works as it should.

using PX.Data;
using PX.Objects.GL;

namespace PX.Objects.AR
{
    // Acuminator disable once PX1016 ExtensionDoesNotDeclareIsActiveMethod extension should be constantly active
    public class CustomerMaint_Extension : PXGraphExtension<PX.Objects.AR.CustomerMaint>
    {
        #region Event Handlers
        protected void _(Events.FieldDefaulting<Customer, Customer.cOrgBAccountID> e)
        {
            Customer row = e.Row;
            Branch company = PXSelect<Branch, Where<Branch.branchID, Equal<Current<AccessInfo.branchID>>>>.Select(Base);

            int branch = company.BAccountID.GetValueOrDefault();
            e.Cache.SetValueExt<Customer.cOrgBAccountID>(row, branch);
        }
    #endregion
  }
}

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings