'Create a vendor selector in Expense claim screen

I am trying to create a Field to store 'VendorID', in my own DAC.

First I tried using Acumatica attributes to show the selector, like the below

[VendorNonEmployeeActive(Visibility = PXUIVisibility.SelectorVisible, DescriptionField = typeof(Vendor.acctName), CacheGlobal = true, Filterable = true)]

AND

[POVendor(Visibility = PXUIVisibility.SelectorVisible, DescriptionField = typeof(Vendor.acctName), CacheGlobal = true, Filterable = true)]

AND other few attributes. but either it shows employee data or nothing. I even tried to write a selector of my own as below where BAccountRef is a class derived from BAccount.

[PXSelector(typeof(Search2<Vendor.bAccountID,
                                    InnerJoin<BAccountRef, On<Vendor.bAccountID, Equal<BAccountRef.bAccountID>>>,
                                    Where<Vendor.status, Equal<BAccountRef.status.active>,
                                    And<Vendor.type, Equal<BAccountType.vendorType>>>>), new Type[] { typeof(BAccountRef.acctCD), typeof(BAccountRef.acctName) },
                               SubstituteKey = typeof(BAccountRef.acctCD))]

Unfortunately no luck, from the behaviour, it seems like the records are auto filtered to show employee info. I cant figure out how this is happening. How to make the selector show vendor info? How this is auto filtering the employees in this graph?



Solution 1:[1]

Most likely your BQL queries towards Vendor DAC are translated into SQL queries to EPEmployee table. This behavior is caused by the EPEmployee cache (and therefore the BAccount cache) initialized prior to Vendor cache.

Try using PX.Objects.AP.VendorAttribute together with the BAccountR DAC - use of BAccountR will break inheritance between the Vendor and BAccount' DACs and should be translated into SQL queries towardsBAccountandVendor` tables:

[Vendor(typeof(Search<BAccountR.bAccountID,
    Where<BAccountR.type, Equal<BAccountType.companyType>, 
        Or<Vendor.type, NotEqual<BAccountType.employeeType>>>>), 
    Visibility = PXUIVisibility.SelectorVisible, CacheGlobal = true, Filterable = true)]
[PXRestrictor(typeof(Where<Vendor.status, IsNull, 
                        Or<Vendor.status, Equal<BAccount.status.active>, 
                        Or<Vendor.status, Equal<BAccount.status.oneTime>>>>),
    AP.Messages.VendorIsInStatus, typeof(Vendor.status))]

Solution 2:[2]

Thanks All,

@Ruslan's answer helped to get the correct definition for the selector. When we use BAccountR or VendorR DAC's the SQL is not translating to EPEmployee and hence i am able to get the correct information.

[PXDimensionSelectorAttribute("VENDOR", typeof(Search<VendorR.bAccountID, Where<VendorR.type, Equal<BAccountType.vendorType>,
                                        And<VendorR.status, Equal<BAccount.status.active>>>>), typeof(VendorR.acctCD), new Type[] { typeof(VendorR.acctCD), typeof(VendorR.acctName) })]

Solution 3:[3]

In one of my recent projects I've used the following in order to get VendorCD:

    #region vendor
    public abstract class vendor : PX.Data.IBqlField
    {
    }
    protected string _Vendor;
    [VendorRaw(typeof(Where<Vendor.vendorClassID, Equal<Current<VendorFilter.vendorClassID>>>), 
        DescriptionField = typeof(Vendor.acctName), DisplayName = "Vendor ID")]
    [PXDefault("", PersistingCheck = PXPersistingCheck.Nothing)]
    public virtual string Vendor
    {
        get
        {
            return this._Vendor;
        }
        set
        {
            this._Vendor = value;
        }
    }
    #endregion

Solution 4:[4]

recently I had to add a Vendor Selector on the ExpenseClaimsDetails DAC, after trying several options, this is the one that worked for me:

    [PXDBInt()]
    [PXUIField(DisplayName = "Vendor", Enabled = true)]       
    [PXDimensionSelector("VENDOR", typeof(Search<VendorR.bAccountID, Where<VendorR.vStatus, Equal<VendorStatus.active>>>),
        typeof(VendorR.acctCD),
        new Type[] { typeof(VendorR.acctCD), 
            typeof(VendorR.acctName), 
            typeof(VendorR.vendorClassID),
            typeof(VendorR.taxRegistrationID)},
        Filterable = true, 
        SelectorMode = PXSelectorMode.TextModeSearch,
        DescriptionField = typeof(VendorR.acctName))]
    public int? UsrEVVendorID { get; set; }
    public abstract class usrEVVendorID : PX.Data.BQL.BqlInt.Field<usrEVVendorID> { }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RuslanDev
Solution 2
Solution 3 Yuriy Zaletskyy
Solution 4 Anhy