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

时间:2017-07-11 20:21:55

标签: customization selector acumatica

我为客户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 Customer选择器似乎不起作用。如何将自定义字段添加到ARInvoice客户选择器?

enter image description here

1 个答案:

答案 0 :(得分:3)

请注意,自Acumatica ERP构建#17.201.0043 以来,可以通过自定义自定义为AR Invoices 客户查找定义的列表“选择器列”对话框(可在“自定义管理器”的“数据类”部分中找到)。有关分步说明,请查看以下屏幕截图: enter image description here

在Acumatica ERP ver上修改AR Invoices的客户查询。 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属性失败而不替换选择器最初定义的列? 只要在PXDimensionSelectorAttribute的实例上执行SetColumns方法初始化PXCache之后的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 Customer选择器中添加自定义字段,应该替换为ARInvoice.CustomerID字段声明的所有属性,并在CustomerActive属性中重新定义Customer选择器的列: enter image description here

[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选择器中: enter image description here

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

enter image description here

enter image description here