Monday, 28 November 2016

PXUIEnabled and PXUIRequired Attributes

Hi All,

If you developing something on Acumatica xRP platform you know that changing of the UI fields visibility should be done through PXUIFieldAttribute on the RowSelected event.

This works perfect on small screens with limited number of controls. But most of ERP screens are not really small. So most probably you already saw such types of code on the RowSelected in SOOrderEntry graph and many others.

Not nice and really hard to support.
Luckily now we have a different way to do it:

  • PXUIEnabled - based on provided BQL conditions can automatically change UIFieldAttribute Enabled property.
  • PXUIRequired - based on provided BQL condition can automatically change PXDefaultAttribute PersistingCheck property.
  • PXUIVerify - based on provided BQL condition can automatically change validate that new value meets provided conditions. Also can trigger validation on update of dependent fields,

Usage of PXUIEnabled:

#region isActive
public abstract class isActive : PX.Data.IBqlField
[PXUIEnabled(typeof(Where<isFinancial, NotEqual<True>>))]
[PXUIField(DisplayName = "Active", Visibility = PXUIVisibility.SelectorVisible)]
public virtual Boolean? IsActive { get; set; }

Usage of PXUIVerify:
#region TimeBillable
public abstract class timeBillable : IBqlField { }
[PXDefault(0, PersistingCheck = PXPersistingCheck.Nothing)]
       Switch<Case<Where<isBillable, Equal<True>>, timeSpent,
              Case<Where<isBillable, Equal<False>>, int0>>,
[PXUIField(DisplayName = "Billable Time", FieldClass = "BILLABLE")]
[PXUIVerify(typeof(Where<timeSpent, IsNull,
       Or<timeBillable, IsNull,
              Or<timeSpent, GreaterEqual<timeBillable>>>>),
PXErrorLevel.Error, Messages.BillableTimeCannotBeGreaterThanTimeSpent)]
[PXUIVerify(typeof(Where<isBillable, NotEqual<True>,
       Or<timeBillable, NotEqual<int0>>>),
PXErrorLevel.Error, Messages.BillableTimeMustBeOtherThanZero,
       CheckOnInserted = false, CheckOnVerify = false)]
public virtual int? TimeBillable { get; set; }


Have a nice development!


Alnikko Espina said...

Could make a tutorial on how to assign background color on columns on grid dynamically like for example the color will depend on the status of the grid. Would appreciate much.

Sergey Marenich said...

Thank you for the great idea! I will put it in my list and do soon!