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 structures. You can use the following method to prevent the user from submitting invalid data.
In an inspection application, the inspector specifies the range of a pressure gauge used to take measurements. The inspector then makes a series of measurements. If any measurements are outside of the range of the gauge, the inspector is prevented from submitting the record.
In the Form section, select the nested structure 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., Measurement Invalid)
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
(Measurement >= PressureGaugeMin AND Measurement <= PressureGaugeMax) ? 0 : 1)
- Save the nested structure form
- Create a new field after the nested structure form
- Set the field type to 'Numeric’
- Label the field appropriate (e.g., AnyMeasurementInvalid)
- Change the field to a 'Formula Calculation’
Specify a formula to sum the value of your invalid measurement check within the nested structure
SUM( MeasurementList.MeasurementInvalid )
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.
One of your measurements is outside the range of your pressure gauge, please check your measurements, and retake any which fall outside the range of your gauge
- Publish the application