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

Acumatica中获取Customer的BillCustomerID和BillLocationID报错排查

问题描述

我尝试在ServiceOrderEntry界面,从Customer记录的BillCustomerID和BillLocationID所定义的父客户位置中查找并显示邮箱,编写的代码如下:

protected void FSServiceOrder_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{
      
var row = (FSServiceOrder)e.Row;

CustomerMaint graph = PXGraph.CreateInstance<CustomerMaint>();
graph.BAccount.Current = PXSelect<Customer, Where<Customer.bAccountID,Equal<Required<FSServiceOrder.customerID>>>>.Select(Base, row.CustomerID);

CustomerLocationMaint parentLocationGraph = PXGraph.CreateInstance<CustomerLocationMaint>();

parentLocationGraph.Location.Current = PXSelect<Location, Where<Location.bAccountID, Equal<Required<Customer.billCustomerID>>,And<Location.locationID, Equal<Required<Customer.billLocationID>>>>>.Select(Base,graph.CurrentCustomer.Current.BillCustomerID, graph.CurrentCustomer.Current.BillLocationID);

}

发布时出现编译错误:

[2024-05-29 01:01:21.813] \App_RuntimeCode\ServiceOrderEntry.cs(118): error CS0426: The type name 'billCustomerID' does not exist in the type 'Customer'
[2024-05-29 01:01:21.813] \App_RuntimeCode\ServiceOrderEntry.cs(119): error CS0426: The type name 'billLocationID' does not exist in the type 'Customer'
[2024-05-29 01:01:21.813] \App_RuntimeCode\ServiceOrderEntry.cs(119): error CS1061: 'Customer' does not contain a definition for 'BillCustomerID' and no accessible extension method 'BillCustomerID' accepting a first argument of type 'Customer' could be found (are you missing a using directive or an assembly reference?)
[2024-05-29 01:01:21.813] \App_RuntimeCode\ServiceOrderEntry.cs(119): error CS1061: 'Customer' does not contain a definition for 'BillLocationID' and no accessible extension method 'BillLocationID' accepting a first argument of type 'Customer' could be found (are you missing a using directive or an assembly reference?)
[2024-05-29 01:01:21.813] \App_RuntimeCode\ServiceOrderEntry.cs(118): error CS0426: The type name 'billCustomerID' does not exist in the type 'Customer'

我已确认Customer的DAC中定义了BillLocationID和BillCustomerID字段,且这些字段在CustomerMaint的CurrentCustomer视图中定义,请问我哪里操作有误?

问题分析与解决

错误原因

  1. 字段名大小写不匹配:C#是大小写敏感语言,你在PXSelect查询中使用了小写开头的billCustomerID和billLocationID,但DAC中字段采用PascalCase命名规范(BillCustomerID和BillLocationID),导致编译器无法识别这些字段。
  2. 冗余Graph实例引发类型问题:你创建了CustomerMaint和CustomerLocationMaint实例来获取记录,不仅增加了不必要的性能开销,还可能出现类型匹配问题(比如graph.BAccount.Current的类型是BAccount,而非Customer)。

修正后的代码

protected void FSServiceOrder_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{
    var row = (FSServiceOrder)e.Row;
    if (row == null) return;

    // 查询当前服务订单关联的Customer记录
    Customer customer = PXSelect<Customer, 
        Where<Customer.bAccountID, Equal<Required<FSServiceOrder.customerID>>>>.Select(Base, row.CustomerID);
    if (customer == null) return;

    // 确保账单客户ID和位置ID不为空,再查询对应位置记录
    if (customer.BillCustomerID != null && customer.BillLocationID != null)
    {
        Location billLocation = PXSelect<Location, 
            Where<Location.bAccountID, Equal<Required<Customer.BillCustomerID>>, 
            And<Location.locationID, Equal<Required<Customer.BillLocationID>>>>>.Select(Base, customer.BillCustomerID, customer.BillLocationID);
        
        // 将位置邮箱赋值到界面扩展字段(示例:假设扩展字段为UsrBillEmail)
        FSServiceOrderExt orderExt = cache.GetExtension<FSServiceOrderExt>(row);
        orderExt.UsrBillEmail = billLocation?.Email;
    }
}

优化说明

  • 移除冗余的Graph实例,直接通过PXSelect查询获取记录,提升代码执行效率。
  • 增加空值判断逻辑,避免空引用异常。
  • 修正PXSelect中的字段名大小写,严格匹配DAC的命名规范。
  • 示例中展示了将查询到的邮箱赋值到ServiceOrder扩展字段的方式,可根据实际界面字段调整。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 09:43:16