Validate data within nested structures
In Flowfinity, there are several ways of validating user data, including:
- Selecting the appropriate field type (eg. email field for email addresses)
- Using the 'Mandatory' field attribute
- State validation rules
You can use state validation rules to prevent a record from being submitted based on other data in the same form. However, state validation rules do not allow you to directly validate data in nested fields. You can use the following method to prevent the user from submitting invalid data.
➤ Learn more about Flowfinity No-Code Platform.
Example
In an inspection application, the inspector is using a particular pressure gauge used to take measurements. The pressure gauge range is copied into the form through a lookup. If any measurements are outside of the range, the inspector made an invalid measurement is prevented from submitting the record.
Instructions
- In the Form section, select the nested field containing the values to be validated (e.g., Measurements List) and click on the Customize Nested Form link.
- Create a new Numeric field. This field will indicate if the nested record contains an invalid value.
- Label the field appropriately (e.g., Invalid Measurement).
- Click on the 'Abc' icon for the field, then select 'Formula Calculation.'
-
In the Formula box, specify a formula that returns a 1 if the nested list field is invalid, or 0 if the value is valid.
For example:
(Measurement >= PressureGaugeMin AND Measurement <= PressureGaugeMax) ? 0 : 1) - To easily show the user that the measurement is invalid, you can also add color rules to the nested field, such as coloring the field red. Click on the top bar of the nested field, and click 'Add color rule.'
- Create the conditions under which the field should be colored.
- Save the nested field.
- Create a new field after the nested field.
- Set the field type to 'Numeric.'
- Label the field appropriate (e.g., Invalid Measurements Total).
- Change the field to a 'Formula Calculation.'
-
Specify a formula to sum the value of your invalid measurement check within the nested structure
For example:
SUM( MeasurementsList.InvalidMeasurement ) -
In the Operations section, determine the target state of the operation used to record measurements.
- In the States tab, select 'Edit state.'
- In the Validation rules tab, click 'Add validation rules' to create a state validation rule.
- Update the condition to indicate that that the field you created in step 8 must equal a constant value of 0.
-
Provide an appropriate error message.
For example:
One of your measurements is outside the range of your pressure gauge. Please check your measurements and retake any which fall outside the correct range. - Publish the application.