This code will check an open test field and compare results in a drop down list, this will ensure that no duplicate data is added into the DB. The drop down is populated from a Database table
var qn = f(CurrentForm());
if(qn.toBoolean())
{
var lookupQn = f(‘HiddensinglewiththeDBtable‘);
var codes = lookupQn.domainValues();
var consultantFound = false;
//go through each table lookup record
for(var i = 0; i < codes.length; i++)
{
//set lookup question so that we can grab the label value
lookupQn.set(codes[i]);
//grab label
var consultant = lookupQn.valueLabel();
//grab user entered value
var userInput = qn.get();
//make both inputs lowercase
consultant = consultant.toLowerCase();
userInput = userInput.toLowerCase();
//replace the space characters (in case users press space twice by mistake)
consultant = consultant.replace(/ /g,””);
userInput = userInput.replace(/ /g,””);
//check if label matches user value
if(consultant == userInput) { consultantFound = true; }
}
if(consultantFound)
{
RaiseError();
SetQuestionErrorMessage(2057,”This string appears to be in the dropdown list“);
}
}