Detect Duplicate Form Records
Duplicate detection checks whether a newly entered record matches—or is likely to match—an existing record, helping prevent duplicate patients, customers, or registrations. Unlike mis-keyed variation detection, which flags possible spelling mistakes, duplicate detection determines whether the person or organization already exists and whether a new record should be created.
To implement duplicate detection in SurveyJS, handle the onServerValidateQuestions event, compare the submitted data against your registry using exact and approximate matching, populate the errors object with field-level messages, and call complete().
How This Demo Works
- Click Fill Sample Data to load a near-match example (
Jon Smithwith DOB1987-04-12), or enter values manually. - When you click Register Participant, SurveyJS raises the
onServerValidateQuestionsevent. - The event handler compares the submitted data with an in-demo participant list (with a short delay to simulate an API call).
- Exact email or participant ID matches produce duplicate errors. Strong matches based on name, date of birth, and phone number produce possible-duplicate warnings. Messages do not reveal details of existing records.
| Try this | Expected result after submission |
|---|---|
Email john.smith@email.com |
Duplicate detected (email) |
Participant ID EXT-9001 |
Duplicate detected (participant ID) |
Name Jon Smith + DOB 1987-04-12 |
Possible duplicate |
Name Sofia Martinezz + DOB 1985-01-22 |
Possible duplicate |
Connect to an API Endpoint
To check against your CRM, EHR, or study database, call your duplicate-detection endpoint from onServerValidateQuestions. Populate the errors object with the returned messages, then call complete():
function validateDuplicateRecordsAsync(_, { data, errors, complete }) {
fetch("/api/validation/duplicates", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
fullName: data.fullName,
dateOfBirth: data.dateOfBirth,
email: data.email,
phone: data.phone,
participantId: data.participantId
})
})
.then((response) => response.json())
.then((result) => {
// Example: { errors: { email: "Duplicate detected..." } }
Object.keys(result.errors || {}).forEach((name) => {
errors[name] = result.errors[name];
});
complete();
})
.catch(() => {
errors["fullName"] = "Duplicate check service is temporarily unavailable. Try again.";
complete();
});
}
survey.onServerValidateQuestions.add(validateDuplicateRecordsAsync);