Skip to main content
Answer

PXFormula issue in modern UI.

  • July 29, 2025
  • 3 replies
  • 99 views

Hello:

We’re looking at the feasibility of converting to modern UI in production when it leaves the Beta.

I’ve ran into several interesting things, but one that feels concerning in the long run.  It is common in our custom code to have DAC’s with properties decorated as the following example:

 [PXFormula(typeof(Selector<MyCustomClass.vendorID, Vendor.acctName>))]

In classic UI, these formulas are calculated correctly as soon as the DAC is exantlated (as expected?).

However, in modern UI, the above PXFormula is never calculated (verified with a break point put on an explicit setter).  This was a bit of a surprise as we were tending to approach the UI as being two different display layers - ‘views’ - built on top of the underlying model and controller.  

  1. Is this a bug?​​​​
  2. If not a bug is the construction we are using deprecated or invalid and only working unintentionally?
  3. is there a property in the PXFormula that would make this work?
  4. If not can you suggest an alternative approach?

We seem to be mostly using this in cases where we want another field to display whenever the selector (in this case for vendorID) is changed, such as wanting to display the account CD and description in separate columns or fields.

Cordially,
Matt Reynolds

Best answer by Marco Villasenor

You are correct in describing the behavior, that value will be updated on insertion or update of the row, specifically whenever vendorID changes. The value is then stored in the DB so next time you show that row the value is already there.

Your last reply made me think that your field is not persited to the database. Is that the case?
If  your field is PXString and not PXDBString you could consider using PXDBScalar to always generate the value for your field. 

 

[PXString()]
[PXDBScalar(typeof(Selector<MyCustomClass.vendorID, Vendor.acctName>))]
[PXUIField(DisplayName = "Account", Enabled = false)]
public virtual String UsrYourField { get; set; }

 

3 replies

Marco Villasenor
Jr Varsity II
Forum|alt.badge.img+2

Hi, I’m not sure if it is a bug, but in the meantime you could try to leverage PXDefault and the Default<> function in PXFormula to trigger the update on DAC instance creation and when the vendorID field changes. I’m not sure if this will behave differently with the MUI:

 

#region UsrYourField
[PXDBString()]
[PXFormula(typeof(Default<MyCustomClass.vendorID>))]
[PXDefault("",
Formula = typeof(Selector<MyCustomClass.vendorID, Vendor.acctName>),
PersistingCheck = PXPersistingCheck.Nothing)]
[PXUIField(DisplayName = "Account", Enabled = false)]
public virtual String UsrYourField { get; set; }

public abstract class usrYourField : BqlType<IBqlString, String>.Field<usrYourField> { }

#endregion

Here is the reference:

Default : IBqlCreator, IBqlTrigger
Raises the FieldDefaulting event for the field to which the PXFormula attribute is attached once the specified field changes.


Type Parameters:

  • V1 : IBqlField

  • Author
  • Freshman II
  • July 30, 2025


@Marco Villasenor 

Perhaps I’m not doing something right, but the above code template appeared to cause loss of functionality in both classic and modern UI, with the formula field only populating when the record was updated or inserted.  I’m not sure that defaulting events are triggered when objects are exantlated and loaded into the cache unless they are ‘new’ objects, but perhaps I’m mistaken.

Ideally I’d like to avoid such a drastic change in the code behind as there are about 60 cases of using “PXFormula<Selector<” as a pattern in the existing customizations.


Marco Villasenor
Jr Varsity II
Forum|alt.badge.img+2

You are correct in describing the behavior, that value will be updated on insertion or update of the row, specifically whenever vendorID changes. The value is then stored in the DB so next time you show that row the value is already there.

Your last reply made me think that your field is not persited to the database. Is that the case?
If  your field is PXString and not PXDBString you could consider using PXDBScalar to always generate the value for your field. 

 

[PXString()]
[PXDBScalar(typeof(Selector<MyCustomClass.vendorID, Vendor.acctName>))]
[PXUIField(DisplayName = "Account", Enabled = false)]
public virtual String UsrYourField { get; set; }