Skip to main content
Solved

Enbale Custom Field on a Grid

  • 16 July 2024
  • 1 reply
  • 39 views

Good day,

I am having an issue making available a custom field on the grid of Bills and Adjustments. I made the field available for the Workflow and I added an Event that has worked for me on other projects, but this time is not working properly. Even if I have PXUIFieldAttribute.SetEnabled the field is not available after closing a bill, but if use the line Base.Transactions.Cache.AllowUpdate = true then it will make available the custom field plus some other Acumatica fields that should not be available when the bill is closed, How can I make only my custom field available?

  protected virtual void _(Events.RowSelected<APTran> e, PXRowSelected baseHandler)
{
APTran line = e.Row;
if (line == null) return;
APTranExt fieldExt = line.GetExtension<APTranExt>();
if (fieldExt == null) return;
baseHandler?.Invoke(e.Cache, e.Args);
//Base.Transactions.Cache.AllowUpdate = true;
PXUIFieldAttribute.SetEnabled<APTranExt.usrTaxLineField>(e.Cache, line, true);

}

 

1 reply

Badge +12

I’d like to point out a couple things:

  1. By putting baseHandler?.Invoke() after multiple null-checks, you’re preventing the base method from running in cases where the row is null
  2. It seems like you could enable the field whether the extension is null or not

I would suggest writing it like this instead:

protected virtual void _(Events.RowSelected<APTran> e, PXRowSelected baseHandler)
{
APTran line = e.Row;

baseHandler?.Invoke(e.Cache, e.Args);

PXUIFieldAttribute.SetEnabled<APTranExt.usrTaxLineField>(e.Cache, null, true);

if (line is null) return;

//Base.Transactions.Cache.AllowUpdate = true;
}

A couple notes:

  1. Notice .SetEnabled() is before the null-check.
  2. Also notice, rather than passing line to it, we pass null. That will enable it automatically for all lines

Finally, since you mentioned workflow, where workflow is concerned, it is usually necessary to use Base.Transactions.Cache.AllowUpdate = true 

If the above code does not change anything, you’ll probably need to use it. If additional fields are enabled, consider disabling them manually?

Reply