如何在事件处理程序中使用 acumatica 自定义属性?

How can I use acumatica custom attribute in Event Handler?

我需要使用我的自定义属性来触发事件,在这种情况下我需要 usrTextileItem==true 来触发 usrTextileItemType 字段为 visible=true。

这是我的纺织品延期声明

[PXBool]
[PXUIField(DisplayName="Textile Item")]

这是我的纺织品项目类型扩展声明

[PXDBString(1)]
[PXUIField(DisplayName="Textile Item Type", Visible=false)]
[PXDefault("C")]
[PXStringList(
new string[]{
"C","Y","B","F"   
},
new string[]{
"Cotton", "Yarn","Beam","Finish Goods"
})]

这是我目前的 InventroyMaint__Extension

protected void InventoryItem_UsrTextileItem_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{

  InventoryItem row = (InventoryItem)e.Row;
  InventoryItemExt ext = cache.GetExtension<InventoryItemExt>();

 if(ext.usrTextileItem==true){ 
    PXUIFieldAttribute.SetVisible<InventoryItemExt.usrTextileItemType>(cache, row, true);
 }

}

我无法获取扩展值,并且出现 3 个错误: 第一个错误:

'PX.Data.PXCache' does not contain a definition for 'GetExtension' and the best extension method overload 'PX.Data.PXCacheEx.GetExtension(PX.Data.IBqlTable)' has some invalid arguments in file: Code#InventoryItemMaint(37)

Instance argument: cannot convert from 'PX.Data.PXCache' to 'PX.Data.IBqlTable' in file: Code#InventoryItemMaint(37)

'usrTextileItem': cannot reference a type through an expression; try 'PX.Objects.IN.InventoryItemExt.usrTextileItem' instead in file: Code#InventoryItemMaint(39)

代码无法编译,但即使编译也无法运行。 SetVisibleSetEnabled 或任何其他影响 UI 的调用不应从 FieldUpdated 事件中完成。你应该从 RowSelected 开始。这在开发人员培训材料中有所介绍;我建议您查看事件的工作原理以及当您更改值并执行回调时它们的处理顺序。

P.S。 cache.GetExtension<T>(); 需要一个参数 - 将其替换为 cache.GetExtension<InventoryItemExt>(row);