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.