Is it possible to alert the user of the duplicate records

Hello Team
I am asking whether it is possible to alert the user that the entry they are about to save is already in the database. How do we avoid deduplication in odk-x?

Any help please. I will really appreciate

1 Like

Hi @hissdev!

If you are using ODK-X to create the identifiers (the uuid) you would never end up with two of the same uuid, so duplication would be avoided. But if you are meaning to avoid two records for the same patient, for example, that you would have to program in. For example if there is a unique identifier, you can mandate that it is entered once and only once by counting the number of times it is already in the database using async_assign (see customizing prompts here: Using ODK-X XLSX Converter — ODK-X Docs). We do something similar in making sure people record only one father in 2_2_Father’s Characteristics section of this form quest2_00_0_ELMPS.xlsx (727.8 KB)
The zcheck_father variable is assigned based on a query counting the number of fathers an individual has entered, and it must be exactly one. You could do something similar for any kind of duplication you want to check for. The key is to set up the query with the right variables that should only occur in unique combination once.


A phone number can be a good method of detecting possible duplicates.

Also remember it’s possible to point out the duplication and ask the user filling out the form to check they are not the same.

As @elmps2018 has stated it requires adding custom formulas and queries to your form.

Many many thanks @elmps2018
I am unable to access the xlsx’s.Please reload the excel files

Excel should be fixed!

Many many thanks @elmps2018
I have tried modifying the codes to mimic what I want but still am having duplicates in my database.
I have one form, one unique identifier and one table
my_unique identifier is pid which is asked once.There are no other variables that I can make it a composite unique key.
Am still getting duplicates please help review code as attached
pdemo.xlsx (11.8 KB)

Hi @hissdev! So I see your query, which looks right, but then I am not seeing any constraint. The query won’t prevent someone from creating a duplicate but it will prevent them from proceeding when they do so due to the constraint. You’ll need to add the constraint pieces like in the example I shared.

Many thanks @elmps2018
I have added the constraint but its preventing me from proceeding.
pdemo.xlsx (13.4 KB)
please help am stuck

Yes, this is the idea, it should not be able to proceed if there are multiple observations (more than one). If it’s not working properly, you’ll need to investigate what exactly the error message is. You would want to go into tables and examine the check_id variable to see if it is present and has the expected value. I don’t see a model tab, and assigned variables need to be defined in the model table with their type to work correctly – that may be one of the problems.

1 Like

Agree with @elmps2018.

Also you might need to design the behavior into the form to help steer the user to fix the problem if not obvious to the user what to do. I often use an “if” with a prompt that explains what to do if the constraint check is invalid.