Knowledge BaseHow to use Autopilot Process SetupHow do I validate a field to ensure a field’s entry is unique?

How do I validate a field to ensure a field’s entry is unique?

Capturing data such as ID's and unique values can become messy if the same value is captured more than once in your Master data list. Autopilot allows you to validate a field so that the value entered is unique, preventing duplication of the data.

 

REMEMBER: You must create your Automated step to add to the master data list before configuring the below. See: How do I populate a master data list from a workflow?

Step 1: Get your list's "Internal List Name"

In the script that is used to validate the field (script given below) We require the Internal list na,e to be used.

  • Click on Master Data
  • Click on the list that you want to write the data to
  • Click on Edit List
  • Copy the Internal List name (as shown above)

Step 2: Add a Dummy field on your form

Step 2: Add a Dummy field on your form

We use a Dummy field on the form, (which is NEVER visible to the user) to store a value which is used to determine if your Unique Field actually has unique data captured.

  • Add a new field on the form. (To learn how to add a field on the form, See: How do I add/ remove a field?)
  • Type of control must be a Yes/No radio button
  • Set the Is Required, Is Enabled and Is Visible settings to NEVER.
  • Click on Save once you done.

N.B Please take note of the fields unique key value. (This will be used in the script below)

Step 3: Add the script to the Unique field

Step 3: Add the script to the Unique field

On the field that requires the values entered to be unique, Click on the Settings icon (as shown above)

Step 3.1: Adding the script to the Field Settings

Step 3.1: Adding the script to the Field Settings

Below is the script used to validate the field's data. Copy and Paste this script into he section that reads "Execute the following when the field's value changes" (As shown above)

Replace all the text in red with the values from step 1 and 2 respectively.

LookupList_97 => The list's internal name from step 1

isunique => The dummy field's unique field key from Step 2

Click on Save once complete

Script:

if (value != undefined || value != null || value.length > 0)

{

   UI.utils.dialog_overlay(true);

   var parameters = "SearchText="+value.toString();

   form.utils.getIntergrationData("LookupList_97",parameters,

   function(results){

       if (results.length > 0)

       {

           var matchFound = false;

           for (var i = 0; i < results.length; i++) {

               var item = results[i];

               if (item.Title.toLowerCase() == value.toLowerCase())

               {

                   matchFound = true;

               }                

           }

           if (matchFound)

           {

               UI.instance.formdata.isunique(0);

               //make control invalid

           }

           else

           {

               UI.instance.formdata.isunique(1);

           //make control valid

           }            

       }

       else

       {

           UI.instance.formdata.isunique(1);

           //make control valid

       }

       UI.utils.dialog_overlay(false);

       }

       , function(){UI.instance.formdata.isunique(1); UI.utils.dialog_overlay(false);})        

}

Step 4: Add validation to the unique field

Step 4: Add validation to the unique field

On the field that requires the values entered to be unique, Click on the Wand icon (as shown above)

Step 4.1: Field Validation

Step 4.1: Field Validation

Enter the below validation in the space provided (as shown above)


$isunique$() == 1

Replace isunique with the Dummy field's key that you have got in step 2.

 

Click on Save once complete.