Acumatica中使用FieldUpdated/FieldDefaulting替代PXFormula实现字段取值咨询
Acumatica 自定义关税码字段事件实现方案
可以通过FieldUpdated方法实现相同效果,你之前的代码未生效主要有两个原因:
- 仅适配了销售订单界面的SOLine实体,未覆盖发票界面Add SO Line对话框使用的SOLineForDirectInvoice投影实体
- 缺少空值校验,可能因空引用异常导致逻辑中断
完整实现代码
你只需要去掉原有SOLineExt字段上的PXFormula特性,补充对应事件即可,代码如下:
public class SOLineExt : PXCacheExtension<PX.Objects.SO.SOLine> { #region UsrTariffCode [PXDBString(30)] [PXUIField(DisplayName = "Tariff Code", Enabled = false)] // 移除原有的PXFormula特性 public virtual string UsrTariffCode { get; set; } public abstract class usrTariffCode : PX.Data.BQL.BqlString.Field<usrTariffCode> { } #endregion // 适配销售订单界面行操作的InventoryID更新事件 protected void _(Events.FieldUpdated<SOLine, SOLine.inventoryID> e) { SOLine row = e.Row; if (row?.InventoryID == null) return; InventoryItem item = PXSelectorAttribute.Select<SOLine.inventoryID>(e.Cache, row) as InventoryItem; if (item != null) { e.Cache.SetValueExt<SOLineExt.usrTariffCode>(row, item.HSTariffCode); } } // 新增适配发票界面Add SO Line对话框的InventoryID更新事件 protected void _(Events.FieldUpdated<SOLineForDirectInvoice, SOLineForDirectInvoice.inventoryID> e) { SOLineForDirectInvoice row = e.Row; if (row?.InventoryID == null) return; InventoryItem item = PXSelectorAttribute.Select<SOLineForDirectInvoice.inventoryID>(e.Cache, row) as InventoryItem; if (item != null) { e.Cache.SetValueExt<SOLineForDirectInvoiceExt.usrTariffCode>(row, item.HSTariffCode); } } } // SOLineForDirectInvoice扩展定义保持不变即可 public class SOLineForDirectInvoiceExt : PXCacheExtension<PX.Objects.SO.DAC.Projections.SOLineForDirectInvoice> { #region UsrTariffCode [PXDBString(50, BqlField = typeof(SOLineExt.usrTariffCode))] [PXUIField(DisplayName = "Tariff Code", Enabled = false)] public virtual string UsrTariffCode { get; set; } public abstract class usrTariffCode : PX.Data.BQL.BqlString.Field<usrTariffCode> { } #endregion }
验证注意事项
- 代码修改完成后需要完整发布自定义项目,清理浏览器缓存后再测试,避免前端缓存导致修改不生效
- 如果需要支持历史已存在的销售订单行批量回填关税码,可以额外在对应图表的RowSelected事件里补充赋值逻辑,正常新增/修改行场景用FieldUpdated已经足够
内容的提问来源于stack exchange,提问作者Erick
相关产品推荐
相关产品推荐

