Skip to main content

Reacting to Value Changes

The onValueChange process of an entity field is executed whenever the value of the field changes. It is the place for logic that has to react to a change of a value — for example, adapting dependent fields, updating state, or triggering follow-up calculations.

When the onValueChange process is executed​

The process only runs when the new value differs from the last value. Delivering the same value again does not trigger the process. The initial value that a field receives — from the RecordContainer or from its own valueProcess — is not treated as a change and therefore does not trigger the process.

Whether a specific source of a change triggers the process is configured with the onValueChangeTypes property of the entity field. Available change types include:

  • MASK — the value was changed by an explicit user interaction, e.g. the user types something into a text field.
  • PROCESS — the valueProcess of the field produced a new value that is different from the last value.
  • PROCESS_SETVALUE - the value is changed by a neon.setFieldValue or vars.set call.

When to use onValueChange vs. valueProcess​

The valueProcess of a field is automatically re-evaluated when one of its dependencies changes. That's why the onValueChangeProcess should only be used to react to changes when the exact source of the change matters, e.g. only when the user changed the field value (see onValueChangeTypes).

Example​

A field TICKET_TYPE should automatically write a text template to the field DESCRIPTION when a new value is selected by the user and ignore any existing description. For this to work, the change type MASK has to be enabled for TICKET_TYPE.

The onValueChange process of TICKET_TYPE would look like this:

let selectedType = vars.get("$local.value");
let ticketTemplate = getTemplateText(selectedType);
neon.setFieldValue("DESCRIPTION", ticketTemplate);