Prevent Duplicate Data Entries in Controls
- Last UpdatedJun 25, 2024
- 2 minute read
You can prevent duplicate data entries in controls for records.
In this example, we create a form with the fields, Bill Ref No. , Bill Date, and Amount. When you add multiple records, and enter same values for the BIll Ref No. , a validation message appears.
-
Create a form. Here, we have named it Duplicate Validation Sample.
-
Add a Base Form control to the form and name it Bill Details.
-
Add a Text control to the Base Form control and modify the properties of the Text control as follows:
-
In the Basic tab, set the Name property to Bill Ref No. , and XML Node to BillRefNo.
-
In the Scripts tab, set the script for the Validate property as follows:
/*Check for Bill Reference Number duplication in the form.*/var returnObj = new ValidationOptions();
returnObj.isValid = true;
returnObj.message = "";
var currentContainer = control.dataContainerForm;
var currentContainerRecords = currentContainer.records();
var currentRecordIndex = currentContainerRecords.indexOf(control.associatedForm);
for (var i = 0; i < currentContainerRecords.length; i++)
{
// Need not check for duplicate values in the same record.
if (currentRecordIndex !== i)
{
if (currentContainerRecords[i].findChildRecordControlByXmlNode("BillRefNo").value.toLowerCase() === currentValue.toLowerCase())
{
returnObj.isValid = false;
returnObj.message = "Duplicate values are not allowed";
break;
}
}
}
return returnObj;
-
-
Add a Date control, and name it Bill Date.
-
Add a Number control, and name it Amount.
-
Save and Publish the form.
-
Preview the form.
-
Enter a value under the Bill Ref No. field.
-
Add another record, and enter the same value again under the Bill Ref No. field.
The following validation message appears below the Bill Ref No. field of the second record:
-
Click Finish. An error message appears. The validation message also appears below the Bill Ref No. field of the first record.