如何将自定义字段添加到 ARInvoice 客户选择器中?

How to add a custom field into the ARInvoice Customer selector?

我为客户 DAC 声明了一个自定义字段:

public class CustomerExt : PXCacheExtension<Customer>
{
    #region UsrDemoField
    [PXDBString(255)]
    [PXUIField(DisplayName = "Demo Field")]

    public virtual string UsrDemoField { get; set; }
    public abstract class usrDemoField : IBqlField { }
    #endregion
}

尝试使用“自定义选择器列”弹出窗口修改 ARInvoice 客户选择器似乎没有效果。如何将我的自定义字段添加到 ARInvoice 客户选择器中?

请注意,自 Acumatica ERP build #17.201.0043 以来,可以自定义为 AR Invoices 的 Customer[=43= 定义的列列表] 通过 Customize Selector Columns 对话框查找(在自定义管理器的数据 Class 部分中可用)。有关分步说明,请查看以下屏幕截图:

修改 AR 发票在 Acumatica ERP 版本上的客户查找。 6.1 及更早版本,请按照以下步骤操作: 由自定义选择器列弹出窗口生成的 PXCustomizeSelectorColumns 的定义与 Acumatica ERP 中的大多数选择器一起出色地工作。基本上,PXCustomizeSelectorColumns 只是在 PXCache 初始化期间用自定义列集替换了选择器最初定义的列:

[AttributeUsage(AttributeTargets.Property | AttributeTargets.Method, AllowMultiple = false)]
public class PXCustomizeSelectorColumns: PXEventSubscriberAttribute
{
    private readonly Type[] _columns;

    public PXCustomizeSelectorColumns(params Type[] columns)
    {
        _columns = columns;
    }

    public override void CacheAttached(PXCache cache)
    {
        cache.SetAltered(this.FieldName, true);
        foreach (PXEventSubscriberAttribute attr in cache.GetAttributes(null, this.FieldName))
        {
            PXSelectorAttribute sel = attr as PXSelectorAttribute;
            if (sel == null) 
                continue;
            sel.SetFieldList(_columns);
            sel.Headers = null;
        }
    }
}

那么什么会导致 PXCustomizeSelectorColumns 属性失败而不替换选择器最初定义的列? 任何时候 SetColumns方法在 PXCache 初始化后在 PXDimensionSelectorAttribute 或 PXSelectorAttribute 的实例上执行,PXCustomizeSelectorColumns 没有机会完成它的工作。

[PXDBInt()]
[PXUIField(DisplayName = "Customer", Visibility = PXUIVisibility.Visible)]
[Serializable]
public class CustomerAttribute : AcctSubAttribute
{
    ...
    public virtual void FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e)
    {
        if (this.AttributeLevel == PXAttributeLevel.Item || e.IsAltered)
        {
            PopulateFields(sender);
        }

        PXFieldSelecting handler = GetAttribute<PXDimensionSelectorAttribute>().FieldSelecting;
        handler(sender, e);
    }

    protected virtual void PopulateFields(PXCache sender)
    {
        if (_FieldList == null)
        {
            _FieldList = new string[this._fields.Length];
            _HeaderList = new string[this._fields.Length];

            for (int i = 0; i < this._fields.Length; i++)
            {
                Type cacheType = BqlCommand.GetItemType(_fields[i]);
                PXCache cache = sender.Graph.Caches[cacheType];
                if (cacheType.IsAssignableFrom(typeof(BAccountR)) ||
                    _fields[i].Name == typeof(BAccountR.acctCD).Name ||
                    _fields[i].Name == typeof(BAccountR.acctName).Name)
                {
                    _FieldList[i] = _fields[i].Name;
                }
                else
                {
                    _FieldList[i] = cacheType.Name + "__" + _fields[i].Name;
                }
                _HeaderList[i] = PXUIFieldAttribute.GetDisplayName(cache, _fields[i].Name);
            }
        }

        var attr = GetAttribute<PXDimensionSelectorAttribute>().GetAttribute<PXSelectorAttribute>();
        attr.SetColumns(_FieldList, _HeaderList);
    }
    ...
}

话虽如此,要将自定义字段添加到 ARInvoice 客户选择器中,应该替换为 ARInvoice.CustomerID 字段声明的所有属性,并在 CustomerActive 属性中重新定义客户选择器的列:

[PXDefault()]
[CustomerActive(typeof(Search<BAccountR.bAccountID>),
    new Type[]
    {
        typeof(BAccountR.acctCD),
        typeof(BAccountR.acctName),
        typeof(CustomerExt.usrDemoField),
        typeof(Address.addressLine1),
        typeof(Address.addressLine2),
        typeof(Address.postalCode),
        typeof(CustomerAttribute.Contact.phone1),
        typeof(Address.city),
        typeof(Address.countryID),
        typeof(CustomerAttribute.Location.taxRegistrationID),
        typeof(Customer.curyID),
        typeof(CustomerAttribute.Contact.salutation),
        typeof(Customer.customerClassID),
        typeof(Customer.status)
    },
    Visibility = PXUIVisibility.SelectorVisible, DescriptionField = typeof(Customer.acctName), Filterable = true, TabOrder = 2)]

发布自定义后,自定义演示字段最终应出现在 ARInvoice Customer 选择器中:

要在 ARInvoice 客户选择器中启用自定义字段搜索,请在布局编辑器中打开发票和备忘录屏幕并键入 UsrDemoField作为客户选择器的 GridProperties.FastFilterFields 属性: