Skip to main content
Answer

Formula Editor having issue in ModernUI

  • July 3, 2025
  • 4 replies
  • 180 views

Forum|alt.badge.img

 I have a screen in Classic UI. there is a Parameters grid in the lower. After adding data to the Parameters grid, it reflected in the Formula Editor when click on Equation field and inside the Fields node. This works correctly in Classic UI like

so, to achieve this, written code in the ASPX.CS file to retrieve parameters inside the Fields node

-------------------------------aspx-----------------

<pxa:PXFormulaCombo ID="edChildField" runat="server" DataField="Equation" EditButton="True"  FieldsAutoRefresh="True" FieldsRootAutoRefresh="true"   LastNodeName="Fields"   PanelAutoRefresh="True" IsInternalVisible="false"  IsExternalVisible="false"   OnRootFieldsNeeded="edOns_RootFieldsNeeded" CommitChanges="true"/>   

-------------aspx.cs:- ------------------------------

protected void edOns_RootFieldsNeeded(object sender, PXCallBackEventArgs e) { 

     EWQCVariableMaint graph = this.ds.DataGraph as EWQCVariableMaint;  

      if (graph != null) { 

         String[] parameters = graph.GetAllParameters(); 

         e.Result = string.Join(";", parameters); 

     } 

 

Similarly, after converting the screen to Modern UI, the Fields node in the formula editor popup does not display the data added in the Parameters tab like

so  on Modern UI

------------------views.ts--------------

export class EWQCVariable extends PXView  {

fieldConfig({

    controlType: "qp-formula-editor",

    controlConfig: {

        dynamicNodeName: "Fields",

        preloadDynamicNode: true,

        comboBox: true

    }

})

Equation: PXFieldState<PXFieldOptions.CommitChanges>;

}

-------------Screen.ts----------

export class QC204000 extends PXScreen {

    Variables = createSingle(EWQCVariable);

}

----------------------screen.html-------------------

<qp-fieldset id="Variables_form011" wg-container="Variables_form" view.bind="Variables" slot="B" >

        <field name="Equation" ></field>

</qp-fieldset>

<qp-tab id="tab1" caption="Parameters">

         <qp-grid id="TestParameters_parameterGrid" view.bind="TestParameters"></qp-grid>

    </qp-tab>

Best answer by darylbowman

This is now graph-based instead of depending upon the aspx.cs file.

  1. Add a class inheriting PX.Data.PXFormulaEditor.OptionsProviderAttribute:
    public class PXFormulaEditor_AddFieldsAttribute : PX.Data.PXFormulaEditor.OptionsProviderAttribute
    {
    public override void ChangeOptionsSet(PXGraph graph, ISet<FormulaOption> options)
    {
    options.Add(new FormulaOption
    {
    Category = $"someCategory",
    Value = $"[{fieldName}]"
    });
    }
    }
  2. Add [PXFormulaEditor_AddFields] to the formula field of your DAC

source

4 replies

MichaelShirk
Captain II
Forum|alt.badge.img+5
  • Captain II
  • August 14, 2025

Hey ​@ashrivastava42 , I don’t have the answer to this, but I have a requirement to implement a custom formula field (classic UI), and I am trying to find documentation on this. 

I have two questions right now that I would appreciate help with.

  1.  What exactly does the “GetAllParameters()” method return?
  2. How is this formula evaluated at runtime, with the current field values passed to those parameters?

 

Any help is greatly appreciated. 

I’ve looked at the article on adding custom DAC objects to the formula builder, but I don’t believe that’s what I need. I just want to add to the “Field” sections, and then evaluate expressions that use values I pass in at runtime. 


darylbowman
Captain II
Forum|alt.badge.img+15
  • Answer
  • August 15, 2025

This is now graph-based instead of depending upon the aspx.cs file.

  1. Add a class inheriting PX.Data.PXFormulaEditor.OptionsProviderAttribute:
    public class PXFormulaEditor_AddFieldsAttribute : PX.Data.PXFormulaEditor.OptionsProviderAttribute
    {
    public override void ChangeOptionsSet(PXGraph graph, ISet<FormulaOption> options)
    {
    options.Add(new FormulaOption
    {
    Category = $"someCategory",
    Value = $"[{fieldName}]"
    });
    }
    }
  2. Add [PXFormulaEditor_AddFields] to the formula field of your DAC

source


darylbowman
Captain II
Forum|alt.badge.img+15

@MichaelShirk - Because I know what you’re attempting to do, you’ll need something like this:

[PXMergeAttributes(Method = MergeMethod.Append)]
[PXFormulaEditor_AddFields]
protected virtual void _(Events.CacheAttached<DXPRSetupExt.usrMyFormulaField> e) { }

public class PXFormulaEditor_AddFieldsAttribute : PX.Data.PXFormulaEditor.OptionsProviderAttribute
{
public override void ChangeOptionsSet(PXGraph graph, ISet<FormulaOption> options)
{
AddFields<BAccount>(graph, options);
AddFields<Contact>(graph, options);
AddFields<Address>(graph, options);
}

void AddFields<T>(PXGraph graph, ISet<FormulaOption> options) where T : class, IBqlTable, new()
{
Type type = typeof(T);

foreach (string field in GetFields<T>(graph))
{
// Skip attributes because we've not implemented them
// TODO : Implement attributes
if (field.EndsWith("_Attributes")) continue;

options.Add(new FormulaOption
{
Category = $"Fields",
Value = $"[{type.Name}.{field}]"
});
}
}
}

private static string[] GetFields<T>(PXGraph graph) where T : class, IBqlTable, new()
{
var select = new SelectFrom<T>.View(graph);

return select.Cache.Fields.ToArray();
}

 


Vignesh Ponnusamy
Acumatica Moderator
Forum|alt.badge.img+5

 

Hi ​@ashrivastava42,

As the formula editor itself is loading fine, I just tested by hardcoding the field names like below which brings up the values in the formula editor, 

public class FeatureMaint_Extension : PXGraphExtension<PX.Objects.AM.FeatureMaint>
{
#region Event Handlers
[ConfigFormulaEditor(DisplayName = "UsrcustValue")]
[PXFormulaEditor_AddFieldsExt]
protected virtual void _(Events.CacheAttached<AMFeatureOptionExt.usrcustValue> e) { }
#endregion

protected class PXFormulaEditor_AddFieldsExtAttribute : PXFormulaEditor.OptionsProviderAttribute
{
public override void ChangeOptionsSet(PXGraph graph, ISet<FormulaOption> options)
{

var designer = (FeatureMaint)graph;
foreach (var parameter in designer.GetAllAttributes())
{
options.Add(new FormulaOption
{
Category = $"Fields",
Value = parameter
});
}

var g = (FeatureMaint)graph;
var fields = new List<string> { "FieldOne", "FieldTwo", "FieldThree", "FieldFour" };

foreach (var parameter in fields)
{
options.Add(new FormulaOption
{
Category = "Fields",
Value = parameter
});
}
}
}
}

 

For us to check this further, can you please share a small customization project using which we can reproduce the issue?