Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ Work Tasks

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.

  1. Create a form. Here, we have named it Duplicate Validation Sample.

  2. Add a Base Form control to the form and name it Bill Details.

  3. Add a Text control to the Base Form control and modify the properties of the Text control as follows:

    1. In the Basic tab, set the Name property to Bill Ref No. , and XML Node to BillRefNo.

    2. 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;

  4. Add a Date control, and name it Bill Date.

  5. Add a Number control, and name it Amount.

  6. Save and Publish the form.

  7. Preview the form.

  8. Enter a value under the Bill Ref No. field.

  9. 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:

    Duplicate values are not allowed

  10. Click Finish. An error message appears. The validation message also appears below the Bill Ref No. field of the first record.

Related Links
TitleResults for “How to create a CRG?”Also Available in