Unique

Overview

In the process of designing forms within ActivityInfo, maintaining data integrity and preventing duplication is crucial. The Unique property enables you to constrain values entered in a field so that only one record in the form can contain a given value for that field. This article explains how you can use the Unique property to enforce uniqueness constraints for fields, ensuring that specific field values remain distinct across all records within a form.

Behaviour

In a form, if you mark a field as "unique," it means that no two records in your form can have the same value in that particular field. This helps to keep your data clean and prevents any confusion or errors caused by having the same information repeated in different places within the form.

When you set a field as Unique, you will be prevented from adding more than one record:

  • with the same value for that field,
  • within the form where that field is located, and
  • among the records you can view given your permissions.

Because uniqueness is constrained only among records that you can view, it is possible that another record that you are unable to view within the form has the same value for a Unique field.

The uniqueness constraints can be applied to the following field types:

  • Fortnight
  • Serial Number
  • User
  • Date
  • Month
  • Text
  • Week
  • Single selection
  • Calculated
  • Barcode

Setting uniqueness constraints: 

The following steps outline how to enforce uniqueness constraints for fields:

  • Navigate to the relevant form settings to either add a new field or edit an existing one.
  • Navigate to the field settings options on the right side of the Field card editor.
  • Select the "Unique" property for the field. This property is only shown when relevant and applicable to the specific field type.

Both the Key and Unique field properties prevent the addition of duplicate records in a form.” A field can be either "Key" or "Unique," not both. To switch between these properties, uncheck the undesired one. You would set a field as Key rather than Unique if the field contains the values you would like to lookup when referencing that form.

  • Next, confirm your changes by saving the form settings.

When you create or edit a record in a field with a uniqueness constraint, ActivityInfo verifies that relevance and validation rules are respected.

If a user attempts to submit a record with a duplicated value in a unique field, the submission will be rejected and an appropriate error message which reads : "This field must be unique", will be displayed.

Blank or missing values are disregarded in uniqueness computations.

Limits

Uniqueness constraints are not assessed for records entered via collection links, the API and the importer.

Example

Ensuring Unique Beneficiary IDs in Cash Distribution Programs

An example of enforcing uniqueness constraints in ActivityInfo might involve a form used to track beneficiary payments in a cash distribution program. Suppose there's a field designated as "Beneficiary ID" which is marked as unique.

This means that each beneficiary's ID number must be distinct; no two beneficiaries can have the same ID within the form.

If you try to enter a new record with a Beneficiary ID that already exists in the system, the form will reject the submission and display an error message stating, that the field must be unique, thereby preventing duplicate records and maintaining data integrity.

By following these steps, you can confidently enforce uniqueness constraints for fields within ActivityInfo, ensuring that your data remains accurate, distinct, and free from duplication.  

Next item
Explanation