On Change

From Resco's Wiki
Jump to navigation Jump to search
Rules and examples

Warning Work in progress! We are in the process of updating the information on this page. Subject to change.

The On Change rules are checked when any field is modified. Rules are client-side scripts that are executed when a user of the mobile app interacts with the app. Rules are no-code business logic, which are managed using the rules editor, usually in Woodford.

On Change rules are available for the following user interface components:

IsLoaded

IsLoaded is a variable, property which checks whether the form or questionnaire is fully loaded and visible on the screen, with all the values assigned. Use it to differentiate between the initial loading of a form and manual user change.

If IsLoaded Equals True

ChangedItem

The ChangedItem property checks whether the change on the form occurs on the specified field.

If ChangedItem Equals address1_city

Forms

Form is a screen in the application that contains numerous fields which either hold or await the data. Default behavior of an entity form can be changed using form rules. Form rules describe sequences of steps that are executed on form-related events. On change usually serves as a field modification based on input or simple field validation.

Rule execution
  • When you modify any field.
  • When the form is loaded (a new form starts empty, then the values are changed as they are loaded from the database and displayed). This can be disabled by "IsLoaded" condition.
  • When an associated/related record is created or modified. This option must be enabled in the properties of an associated list. Switch to the Properties tab and enable Controls > Trigger OnChange event (more info).
  • Setting a value inside the On Change rule for a field placed on the form triggers the On Change rule again. This can be disabled by "ChangedItem" condition.

Example: Postal code validation

When a user enters information into a field, you may want to verify that the format is correct. In the rule below, we verify that the postal code field matches the expected format.

Postal code validation.png

Note the three conditions:

  • IsLoaded Equals True – because we don’t want to check this condition when opening the form; we want to check the condition when the user makes a change on the field.
  • ChangedItem Equals PostalCode – because we want the rule to be triggered only if the Postal Code field was changed and not any other field on the form.
  • Entity.PostalCode Does Not Match Regex – because we want to check the format of the field after the user changed the value of the field.

Views

On Change rules can be used with views, but only when the Editable field is set. (Editable field, list, or editable grid is a feature that allows users to edit one or more records directly from the view, without a need to go to the form of a record.)

Rule execution
  • When you modify an editable field.

Questionnaires

Editing rules allow you to further customize the questionnaire form’s design and usage (hide or disable form fields, assign values to them, etc.).

Rule execution
  • When any value in the questionnaire is modified
  • When the questionnaire is first displayed
  • When a repeatable group is repeated
  • When a repeatable group is deleted

Example: Additional questions

When a user answers a question in a certain way, you may want to display additional questions. For example, if the answer to the question “Are you married?” is “Yes”, an additional question “Partner's name” is set to be visible.

Additional question.png

Example: Automated date of next inspection

When a user answers a question in a certain way, you might want to change the other questions. For example, you can count the next inspection date based on the periodicity of inspections.

Automated date of next inspection.png

Schedule Board

In the Schedule Board, the On Change rule triggers when a task is rescheduled. The event is triggered when you:

  • drag a task to a different time/resource
  • modify the time or resource on the task properties
Note When you drag a task to a different resource and time, the rule is actually executed three times (every time with a different value in the ChangedItem variable): once for start date, end date, and resource.

The following simple On Change rule appends text to the subject of activity when you reschedule the activity.

On change rule in schedule board.png