Skip to main content

Create a selector from a combo Attribute

  • January 6, 2026
  • 2 replies
  • 106 views
  • Translate All

darylbowman
Captain II
Forum|alt.badge.img+17

This custom C# attribute will create a selector from an Acumatica ‘combo’ attribute.

[PXString(10, IsUnicode = true)]
[PXDBString(10, IsUnicode = true)]
public class DXSelectorFromComboAttributeAttribute : PXCustomSelectorAttribute
{
protected string _AttributeID;

public DXSelectorFromComboAttributeAttribute(string AttributeID)
: base(typeof(CSAttributeDetail.valueID),
typeof(CSAttributeDetail.valueID),
typeof(CSAttributeDetail.description))
{
_AttributeID = AttributeID;
SubstituteKey = typeof(CSAttributeDetail.valueID);
DescriptionField = typeof(CSAttributeDetail.description);
}

public override void FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e)
{
if (_AttributeID is object)
{
var view = new PXView(sender.Graph, true, GetSelect());
view.Clear();

foreach (CSAttributeDetail attributeDetail in view.SelectMulti(_AttributeID))
{
view.Cache.SetStatus(attributeDetail, PXEntryStatus.Notchanged);
}
}

base.FieldSelecting(sender, e);

// Set the display name dynamically (unless overridden by PXUIFieldAttribute)
if (e.ReturnState is PXFieldState state)
state.DisplayName = GetAttributeDescription(sender.Graph);
}

protected virtual string GetAttributeDescription(PXGraph graph)
{
CSAttribute attr = SelectFrom<CSAttribute>
.Where<CSAttribute.attributeID.IsEqual<P.AsString>>
.View.ReadOnly.Select(graph, _AttributeID);
return attr?.Description ?? _AttributeID;
}

protected virtual new BqlCommand GetSelect() =>
new SelectFrom<CSAttributeDetail>
.Where<CSAttributeDetail.attributeID.IsEqual<P.AsString>
.And<CSAttributeDetail.disabled.IsNotEqual<True>>>
.OrderBy<Asc<CSAttributeDetail.sortOrder>>
.View.ReadOnly(_Graph).View.BqlSelect;

public IEnumerable GetRecords()
{
var view = new PXView(_Graph, true, GetSelect());
foreach (CSAttributeDetail row in view.SelectMulti(_AttributeID))
{
yield return row;
}
}
}

It can be used on a persisted or non-persisted field, like this:

[DXSelectorFromComboAttribute("MYATTRIB")]
[PXUIField(DisplayName = "Attribute Selector")]
public virtual string UsrDXAttributeSelector { get; set; }
public abstract class usrDXAttributeSelector : BqlString.Field<usrDXAttributeSelector> { }

 

2 replies

Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • January 6, 2026

Thank you for sharing this with the community ​@darylbowman!

Translate

darylbowman
Captain II
Forum|alt.badge.img+17

Note that you may wish to use this constructor instead in order to show the Attribute ‘option’ instead of the ‘key’ as the selector value.

public DXSelectorFromComboAttributeAttribute(string AttributeID)
: base(typeof(CSAttributeDetail.valueID),
typeof(CSAttributeDetail.valueID),
typeof(CSAttributeDetail.description))
{
_AttributeID = AttributeID;
SubstituteKey = typeof(CSAttributeDetail.valueID);
DescriptionField = typeof(CSAttributeDetail.description);
SelectorMode = PXSelectorMode.DisplayModeText;
}

 

Translate