I want a selector that will let me pick a BAccountID from a list of BAccounts which I filter, but I also want it to have one additional option I can pick “All Trading Partners”. If all I want is to pick a BAccountID then I would just use a vanilla selector, however since I also want that additional option, I’m trying to use a simple Custom Selector here is an example.
Here is the selector
public class SimpleSelectorAttribute : PXCustomSelectorAttribute
{
Serializable]
public class SelectorFields : IBqlTable
{
#region id
public abstract class id : PX.Data.BQL.BqlString.Field<id> {}
PXString]
public virtual string Id {get; set;}
#endregion
#region displayField
public abstract class displayField : PX.Data.BQL.BqlString.Field<displayField>{}
PXString]
public virtual string DisplayField {get; set;}
#endregion
}
public SimpleSelectorAttribute()
: base(typeof(SelectorFields.id))
{
this.SubstituteKey = typeof(SelectorFields.displayField);
}
public virtual IEnumerable GetRecords()
{
yield return new SelectorFields()
{ Id = "*ALL*", DisplayField = "All Trading Partners"};
foreach (BAccount cust in PXSelect<BAccount, Where<ISPSCustomerExtension.iSPSEDICust, Equal<True>>>.Select(this._Graph))
{
yield return new SelectorFields()
{ Id = cust.BAccountID.ToString(), DisplayField = cust.AcctCD };
}
}
}
And this is a field using it
#region testField
public abstract class testField : PX.Data.BQL.BqlString.Field<testField>{}
PXString]
PXUIField(DisplayName = "testField")]
SimpleSelectorAttribute()]
public virtual string TestField{get; set;}
#endregion
This works great, except I need the field to be bound to a DB column so I have to change TestField from PXString to PXDBString. Once I do that(And of course make sure there is a matching column in the table) the selector the column bound to the selector will no longer let me sort or filter it via the Acumatica UI, throwing an “Invalid object name ‘SelectorFields’” error whenever I try. I could both sort and filter before I set the TestField to being bound to the DB.
I’ve also discovered that if I override SubstituteKeyCommandPreparing method inside my custom selector and just leave it blank the error is no longer thrown(Yay) but now when I try to sort the column is being sorted by the Id field instead of the DisplayField field(Boo). Which makes sense if the SubstituteKeyCommandPreparing method is what was applying the substitute key logic in the first place. After more testing I’ve found that the reason the “Invalid object name ‘SelectorFields’” error is being thrown when I try to sort my column is that it is an unbound DAC. When I use a bound DAC the sort/filter “Invalid object” error is not thrown.
If anyone has any thoughts or suggestions I’d appreciate them, adding one additional static element to a selector seems like it shouldn't be that hard, but I’m struggling :)
Philip Engesser