Skip to main content
Solved

How to restrict / override salesperson selector in invoice and memos (ARTran)

  • April 1, 2026
  • 2 replies
  • 31 views

Forum|alt.badge.img+2

 

I needed to restrict the SalesPersonID selection in ARTran so that users can only choose salespersons assigned to their organization, based on a custom field (UsrInternalCompanyID) added to the SalesPerson DAC. To achieve this, I attempted to override the selector using a CacheAttached event with a custom PXSelector that joins the Branch table and filters records according to the current user’s branch/organization. While this approach successfully limited the list of salespersons shown in the UI, it resulted in an issue where the selected value was cleared upon saving the document.

Salesperson DAC extention

    public class SalesPersonAccessRestExtP : PXCacheExtension<PX.Objects.AR.SalesPerson>
{
#region UsrInternalCompanyID
[PXDBInt]
[PXUIField(DisplayName = "Company ID")]
[PXSelector(typeof(OrganizationBAccount.organizationID),
typeof(OrganizationBAccount.acctCD),
typeof(OrganizationBAccount.acctName),
SubstituteKey = typeof(OrganizationBAccount.acctName),
DescriptionField = typeof(OrganizationBAccount.acctName))]
public virtual int? UsrInternalCompanyID { get; set; }
public abstract class usrInternalCompanyID : PX.Data.BQL.BqlInt.Field<usrInternalCompanyID> { }
#endregion
}
public class ARInvoiceEntryAccessRestExtP : PXGraphExtension<PX.Objects.AR.ARInvoiceEntry>
{
#region Event Handlers
[PXMergeAttributes(Method = MergeMethod.Append)]
[PXSelector(
typeof(Search2<
SalesPerson.salesPersonID,
InnerJoin<Branch,r
On<Branch.organizationID,
Equal<SalesPersonAccessRestExtP.usrInternalCompanyID>>>,
Where<Branch.branchID, Equal<Current<AccessInfo.branchID>>>>))]
protected void _(Events.CacheAttached<ARTran.salesPersonID> e)
{

}

following is the default attributes exist in ARTran.salespersonID attribute in core code.

    [SalesPerson]
[PXParent(typeof(Select<ARSalesPerTran, Where<ARSalesPerTran.docType, Equal<Current<tranType>>, And<ARSalesPerTran.refNbr, Equal<Current<refNbr>>, And<ARSalesPerTran.salespersonID, Equal<Current2<salesPersonID>>, And<Current<commissionable>, Equal<True>>>>>>), LeaveChildren = true, ParentCreate = true)]
[PXDefault(typeof(ARRegister.salesPersonID), PersistingCheck = PXPersistingCheck.Nothing)]
[PXFormula(typeof(Switch<Case<Where<lineType, Equal<SOLineType.freight>>, Null>, salesPersonID>))]
[PXForeignReference(typeof(Field<salesPersonID>.IsRelatedTo<SalesPerson.salesPersonID>))]


I tried to use restrictor, but it is not allowed to use joins inside restrictor. so that didn’t work.

Best answer by saco86

Hi ​@PDharmasena10,

 

The Sales Person attribute has other constructor where you can add Where and Join, 

You can remove the Sales Person attribute and add it with the where condition and the join, you can use this code.

[PXMergeAttributes(Method = MergeMethod.Append)]
[PXRemoveBaseAttribute(typeof(SalesPersonAttribute))]
[SalesPerson(typeof(Where<Branch.branchID, Equal<Current<AccessInfo.branchID>>),
typeof(InnerJoin<Branch, On<Branch.organizationID, Equal<SalesPersonAccessRestExtP.usrInternalCompanyID>>>))]
protected virtual void _(Events.CacheAttached<ARTran.salesPersonID> e) { }

 

2 replies

  • Jr Varsity I
  • Answer
  • April 1, 2026

Hi ​@PDharmasena10,

 

The Sales Person attribute has other constructor where you can add Where and Join, 

You can remove the Sales Person attribute and add it with the where condition and the join, you can use this code.

[PXMergeAttributes(Method = MergeMethod.Append)]
[PXRemoveBaseAttribute(typeof(SalesPersonAttribute))]
[SalesPerson(typeof(Where<Branch.branchID, Equal<Current<AccessInfo.branchID>>),
typeof(InnerJoin<Branch, On<Branch.organizationID, Equal<SalesPersonAccessRestExtP.usrInternalCompanyID>>>))]
protected virtual void _(Events.CacheAttached<ARTran.salesPersonID> e) { }

 


Forum|alt.badge.img+2
  • Jr Varsity I
  • April 1, 2026

@PDharmasena10 The salesperson attribute is already putting a selector on that field, so when you just attempt to append a new selector attribute, it is likely causing issues.

 

I would say the simplest option which should work is using the PXRestrictor Attribute in the cacheattached event. Here you can define your additional restrictions on which Salesperson should be available. However, you should also be able to remove the attribute and add it back with the additional parameter as ​@saco86 suggested and get the correct output.