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

Acumatica自定义Customer选择器选中时提示系统找不到'Customer'报错求助

问题根因

  • 核心错误出在自定义选择器的返回值映射逻辑:你给SalesRepCustomer选择器传入的键是Customer.acctCD(字符串类型),但SOOrder.CustomerID字段存储的是int类型的客户主键bAccountID,你没有指定SubstituteKey,系统选中客户后会尝试把字符串格式的acctCD存入int类型的CustomerID字段,后续校验时自然无法匹配到对应的Customer记录,才会报"找不到'Customer'"的错误。
  • 次要问题:GetRecords方法中把当前用户对应的销售代表查询逻辑写在循环内,每遍历一个客户就重复查询一次,会引发严重性能问题,且属于冗余逻辑。
  • 冗余配置:你在DAC扩展中额外加的PXForeignReference特性,原生SOOrder.CustomerID字段已经自带对应的外键配置,重复添加可能引发映射冲突。

修复方案

  1. 给自定义选择器添加SubstituteKey配置,指定选择器返回值为Customer.bAccountID,和SOOrder.CustomerID的字段类型、含义匹配。
  2. 把销售代表查询逻辑移到循环外部,每个请求只查询一次当前用户对应的销售代表。
  3. 移除DAC扩展中冗余的PXForeignReference特性。

修复后代码

DAC扩展部分

[PXNonInstantiatedExtension]
public class SO_SOOrder_ExistingColumn : PXCacheExtension<PX.Objects.SO.SOOrder>
{
    #region CustomerID  
    [PXMergeAttributes(Method = MergeMethod.Merge)]     
    [SalesRepCustomer]  
    public int? CustomerID { get; set; }
    #endregion
}

自定义选择器部分

public class SalesRepCustomer : PXCustomSelectorAttribute
{
    public SalesRepCustomer() : base(typeof(Customer.acctCD))
    {
        this.DescriptionField = typeof(Customer.acctName); // 可根据需求改回acctCD,显示客户名称更友好
        this.SubstituteKey = typeof(Customer.bAccountID); // 新增该行,指定返回客户主键值和目标字段匹配
    }
    protected virtual IEnumerable GetRecords()
    {
        // 查询逻辑移到循环外,仅执行一次
        var accessCache = _Graph.Caches[BqlCommand.GetItemType(typeof(AccessInfo.userName))];
        AccessInfo currentAccess = (AccessInfo)accessCache.Current;
        string userName = currentAccess.UserName;
        SalesPerson currentSalesRep = PXSelect<SalesPerson, Where<SalesPerson.descr, Equal<Required<AccessInfo.userName>>>>.Select(_Graph, userName);

        foreach (Customer pc in PXSelect<Customer>.Select(this._Graph))
        {
            if (currentSalesRep != null)
            {
                CustSalesPeople relation = PXSelect<CustSalesPeople, Where<CustSalesPeople.salesPersonID, Equal<Required<SalesPerson.salesPersonID>>, And<CustSalesPeople.bAccountID, Equal<Required<CustSalesPeople.bAccountID>>>>>.Select(_Graph, currentSalesRep.SalesPersonID, pc.BAccountID);
                if (relation != null)
                {
                    yield return pc;
                }
            }
            else
            {
                yield return pc;
            }
        }
    }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.23 17:54:03