You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

BAccount表自定义字段Cache Attached使用异常及字段更新问题咨询

解决Acumatica中BAccount自定义字段在客户/供应商界面的显示与同步问题

我来帮你搞定这个自定义字段的显示和更新难题!先拆解下你遇到的核心问题,再给你一步步的解决方案:

问题根源分析

  1. PXDBInt报错:直接在Cache Attached里用PXDBInt会和BAccount表中自定义字段的原有属性冲突,因为你没有合并原有属性,相当于重新定义了字段,导致系统识别冲突。
  2. Customer_前缀Cache Attached不更新:Customer_UsrPMEmployee_CacheAttached本质是针对Customer DAC的字段,但你的自定义字段实际属于BAccount,所以保存时系统不会把值写入BAccount表,自然看不到更新。
  3. BAccount_前缀报错:大概率是没有正确合并原有字段属性,或者自定义字段在BAccount上的类型和你Cache Attached里的定义不匹配(比如原字段是PXString但你用了PXDBInt)。

正确解决方案

第一步:确认BAccount自定义字段的基础定义

确保你在BAccount表中创建的UsrPMEmployee字段类型是PXDBInt,并关联到Employee表(和SalesPersonID/BuyerID的类型一致)。

第二步:CustomerMaint扩展图代码(显示销售人员)

在客户界面,我们需要把自定义字段绑定到客户的SalesPersonID,并实现双向同步:

public class CustomerMaint_Extension : PXGraphExtension<CustomerMaint>
{
    // 合并原有字段属性,只修改显示名和选择器
    [PXMergeAttributes(Method = MergeMethod.Merge)]
    [PXUIField(DisplayName = "Salesperson")]
    [PXSelector(
        typeof(Search<Employee.bAccountID, Where<Employee.isActive, Equal<True>>>),
        typeof(Employee.acctName), typeof(Employee.email),
        SubstituteKey = typeof(Employee.bAccountID)
    )]
    public virtual void BAccount_UsrPMEmployee_CacheAttached(PXCache cache)
    {
        // 加载客户时,自动把SalesPersonID赋值到自定义字段
        cache.FieldSelecting.AddHandler<BAccount.usrPMEmployee>((sender, e) =>
        {
            if (e.Row is BAccount bAccount && Base.CurrentCustomer.Current != null)
            {
                e.ReturnValue = Base.CurrentCustomer.Current.SalesPersonID;
            }
        });

        // 修改自定义字段时,同步更新客户的SalesPersonID
        cache.FieldUpdated.AddHandler<BAccount.usrPMEmployee>((sender, e) =>
        {
            if (e.Row is BAccount bAccount && Base.CurrentCustomer.Current != null)
            {
                Base.CurrentCustomer.Current.SalesPersonID = (int?)e.NewValue;
                Base.CurrentCustomer.Update(Base.CurrentCustomer.Current);
            }
        });
    }
}

第三步:VendorMaint扩展图代码(显示采购员)

同理,在供应商界面绑定到BuyerID并双向同步:

public class VendorMaint_Extension : PXGraphExtension<VendorMaint>
{
    [PXMergeAttributes(Method = MergeMethod.Merge)]
    [PXUIField(DisplayName = "Buyer")]
    [PXSelector(
        typeof(Search<Employee.bAccountID, Where<Employee.isActive, Equal<True>>>),
        typeof(Employee.acctName), typeof(Employee.email),
        SubstituteKey = typeof(Employee.bAccountID)
    )]
    public virtual void BAccount_UsrPMEmployee_CacheAttached(PXCache cache)
    {
        // 加载供应商时,自动把BuyerID赋值到自定义字段
        cache.FieldSelecting.AddHandler<BAccount.usrPMEmployee>((sender, e) =>
        {
            if (e.Row is BAccount bAccount && Base.Vendor.Current != null)
            {
                e.ReturnValue = Base.Vendor.Current.BuyerID;
            }
        });

        // 修改自定义字段时,同步更新供应商的BuyerID
        cache.FieldUpdated.AddHandler<BAccount.usrPMEmployee>((sender, e) =>
        {
            if (e.Row is BAccount bAccount && Base.Vendor.Current != null)
            {
                Base.Vendor.Current.BuyerID = (int?)e.NewValue;
                Base.Vendor.Update(Base.Vendor.Current);
            }
        });
    }
}

关键注意点

  • 使用[PXMergeAttributes]:这个特性会保留字段原有属性(比如PXDBInt、IsNullable等),只替换你需要修改的部分(显示名、选择器),避免属性冲突报错。
  • 双向同步逻辑:通过FieldSelecting和FieldUpdated事件,确保自定义字段和原生的SalesPersonID/BuyerID数据一致,加载和保存都能正常工作。
  • 针对BAccount字段做Cache Attached:因为字段实际属于BAccount表,这样保存时系统会正确把值写入数据库,解决之前“保存不更新”的问题。

内容的提问来源于stack exchange,提问作者Sameer Wagh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 09:03:30