Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Generating Inputs

End-users are sometimes able to provide their inputs to various calculations. For example, end-users can provide inputs to dashboards, price lists, quotes — but not to workflows. If user inputs are available, the logic will at some point execute in a special mode, called input generation mode. This execution results in the generation of objects that the frontend application uses to render input fields. When the user has provided values for those input fields and chooses to run the calculation, the logic will execute in regular mode and perform the business logic.

Info
The special execution mode that generates the inputs was formerly called Syntax Sheck mode. This name has been changed in Pricefx version 10.0, but you can still encounter it in older projects.

When a logic is generating the user input fields, the logic does not yet have access to the values of those input fields. Since the results wouldn’t be meaningful, you do not want to execute the code that performs the business logic. There is a special function that allows you to detect whether the logic is currently being executed in input generation mode (api.isInputGenerationExecution()), and another to skip the execution of subsequent elements (api.abortCalculation()).

To keep things simple, adhere to the separation of concerns design principle: let the business logic delegate the input generation to a dedicated form logic (more on this in the next section).

input generation.drawio

In each logic, always let the first element script contain a single call to the Form.build() method:

Expand
titleForm.build()
Code Block
languagegroovy
themeMidnight
linenumbersfalse
libs.Library_Input.Forms.build()

Where the Form.build() is defined as:

Code Block
languagegroovy
themeMidnight
titlehttps://github.com/pricefx/example-configuration/tree/main/pricefxSrc/CalculationLogic/Library_Input/elements/Forms
linenumbersfalse
void build(String formLogicName = null, String label = 'End-user Input') {
    if(!api.syntaxCheck){
        return
    }

    if(formLogicName){
        api.inputBuilderFactory()
                .createConfiguratorInputBuilder('_user_inputs', formLogicName, true)
                .setLabel(label)
                .getInput()
    }

    api.abortCalculation()
}

This will ensure that your business logic is not executed in input generation mode.

Then, if you want to generate inputs, create a so-called form logic (more on this further down) and provide the name of that logic as an argument to Forms.build():

Code Block
languagegroovy
themeMidnight
linenumbersfalse
libs.Library_Input.Forms.build('My_Form_Logic')

See the example configuration for an example.

...