简体   繁体   中英

How can I use acumatica custom attribute in Event Handler?

I need to use my custom attribute to trigger an event, in this case I need usrTextileItem==true to trigger usrTextileItemType Field to visible=true.

here's my Declaration in Extension for Textile Item

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

here's my Declaration in Extension for Textile Item Type

[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"
})]

and this is my current 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);
 }

}

and I can't get the extensions value, and I have 3 error that says: First error:

'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)

The code doesn't compile, but even if it did, it wouldn't work. SetVisible , SetEnabled or any other call affecting UI shouldn't be done from FieldUpdated event. You should do it from RowSelected instead. This is covered during in the developer training materials; I suggest you review how events work and in which order they're processed when you change value and do a callback.

PS cache.GetExtension<T>(); expects a parameter - replace it with cache.GetExtension<InventoryItemExt>(row);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM