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视图中定义,请问我哪里操作有误?
错误原因
- 字段名大小写不匹配:C#是大小写敏感语言,你在PXSelect查询中使用了小写开头的
billCustomerID和billLocationID,但DAC中字段采用PascalCase命名规范(BillCustomerID和BillLocationID),导致编译器无法识别这些字段。 - 冗余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

