# Create unique id for participant

**URL:** <https://forum.odk-x.org/t/create-unique-id-for-participant/485>\
**Category:** Support\
**Created:** [May 2, 2019, 4:22am UTC](https://forum.odk-x.org/t/create-unique-id-for-participant/485 "2019-05-02T04:22:23Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![nsthakuri](https://odkx.b-cdn.net/letter_avatar_proxy/v4/letter/n/82dd89/32.png) [@nsthakuri](https://forum.odk-x.org/u/nsthakuri)\
**Post date:** [May 2, 2019, 4:22am UTC](https://forum.odk-x.org/t/create-unique-id-for-participant/485/1 "2019-05-02T04:22:23Z")

</div>

Hi,  
I am creating a survey form. I would like to create an unique id of each woman. How could I create woman\_id as unique identifier?  
Thanks,  
Narendra[demogForm.xlsx](https://odkx.b-cdn.net/uploads/default/original/2X/f/f46836ab9e11ba3e864e669726c57717e75c6ea5.xlsx) (18.9 KB)

---

<div class="post-metadata">

**Author:** ![elmps2018](https://odkx.b-cdn.net/user_avatar/forum.odk-x.org/elmps2018/32/105_2.png) [@elmps2018](https://forum.odk-x.org/u/elmps2018)\
**Post date:** [May 2, 2019, 7:33pm UTC](https://forum.odk-x.org/t/create-unique-id-for-participant/485/2 "2019-05-02T19:33:02Z")

</div>

Hi @nstharkuri!

So each form will get a unique id (uuid) that you can call on. I would suggest using that to start with. Alternatively, if you have to create a unique id variable that is some combination (like we did household id + line number within household) you can do something like this: [quest1\_03\_0.xlsx](https://odkx.b-cdn.net/uploads/default/original/2X/c/c212d94bf04de16353bfd56289b2bb983028de10.xlsx) (55.2 KB)

Best,  
Caroline

---

<div class="post-metadata">

**Author:** ![ghare](https://odkx.b-cdn.net/letter_avatar_proxy/v4/letter/g/ad7895/32.png) [@ghare](https://forum.odk-x.org/u/ghare)\
**Post date:** [May 2, 2019, 11:17pm UTC](https://forum.odk-x.org/t/create-unique-id-for-participant/485/3 "2019-05-02T23:17:04Z")

</div>

Are you looking to re-use the ID for multiple longitudinal surveys?

---

<div class="post-metadata">

**Author:** ![nsthakuri](https://odkx.b-cdn.net/letter_avatar_proxy/v4/letter/n/82dd89/32.png) [@nsthakuri](https://forum.odk-x.org/u/nsthakuri)\
**Post date:** [May 3, 2019, 4:32am UTC](https://forum.odk-x.org/t/create-unique-id-for-participant/485/4 "2019-05-03T04:32:29Z")

</div>

Thanks @elmps2018,  
@ghare, Yes I am creating the multiple longitudinal survey. The enrollment form would capture an unique woman ID for only one time. we need to validate that each woman\_id is only used one time. Could you please suggest.  
Thanks,  
Narendra

---

<div class="post-metadata">

**Author:** ![elmps2018](https://odkx.b-cdn.net/user_avatar/forum.odk-x.org/elmps2018/32/105_2.png) [@elmps2018](https://forum.odk-x.org/u/elmps2018)\
**Post date:** [May 3, 2019, 5:21pm UTC](https://forum.odk-x.org/t/create-unique-id-for-participant/485/5 "2019-05-03T17:21:55Z")

</div>

There are a couple options here:

1. Preload the ids and not let enumerators edit them; then they will necessarily be unique.
2. If they need to be created in the field, you can check that an id is used once and only once using async\_assign. For example, in section 2\_2 we check that everyone enters data for one and only one father with zcheck\_father: [quest2\_00\_0.xlsx](https://odkx.b-cdn.net/uploads/default/original/2X/e/ec1229a08ea5c7cb71f8761f346af1c7de8c8172.xlsx) (723.1 KB)  
Here’s a zip with the async\_assign:  
[customPromptTypes.js.zip](https://odkx.b-cdn.net/uploads/default/original/2X/5/546147b03e8072a9b7c05268638f7027a59c247d.zip) (2.5 KB)

You need to set up a query (here, count\_fathers) and then async\_assign\_count can count them.

There’s probably some more efficient method as well, but this would at least let you count instances of an id and make sure there is one and only one with a constraint.

Best,  
Caroline

---

<div class="post-metadata">

**Author:** ![nsthakuri](https://odkx.b-cdn.net/letter_avatar_proxy/v4/letter/n/82dd89/32.png) [@nsthakuri](https://forum.odk-x.org/u/nsthakuri)\
**Post date:** [May 10, 2019, 8:45am UTC](https://forum.odk-x.org/t/create-unique-id-for-participant/485/6 "2019-05-10T08:45:55Z")

</div>

Thanks @elmps2018,  
We will assign unique womanID for each woman in the field and data collector inserts into the tablet. We want to prevent womanID duplication when collecting data. When we create an enrollment form for women and each woman gets an unique womanID.  
After reviewing your example, do we need to create a separate table for father enrollment?  
Thanks.

---

<div class="post-metadata">

**Author:** ![elmps2018](https://odkx.b-cdn.net/user_avatar/forum.odk-x.org/elmps2018/32/105_2.png) [@elmps2018](https://forum.odk-x.org/u/elmps2018)\
**Post date:** [May 10, 2019, 9:25am UTC](https://forum.odk-x.org/t/create-unique-id-for-participant/485/7 "2019-05-10T09:25:17Z")

</div>

Hi @nsthakuri!

I think the question of whether you need to do tables and unique ids for fathers really depends on what your data needs are for the project (are you trying to track fathers over time?).

---

<div class="post-metadata">

**Author:** ![nsthakuri](https://odkx.b-cdn.net/letter_avatar_proxy/v4/letter/n/82dd89/32.png) [@nsthakuri](https://forum.odk-x.org/u/nsthakuri)\
**Post date:** [May 10, 2019, 9:37am UTC](https://forum.odk-x.org/t/create-unique-id-for-participant/485/8 "2019-05-10T09:37:13Z")

</div>

Hi @elmps2018,  
We are going to conduct a study, initially we will enroll women through demographic form. Our data collector will insert womanID manually into the tablet. But sometime data collector could mistakenly enter womanID that was previously used. In this situation, we would like to generate alert for data collector to prevent duplicate woman ID.  
For example, womanid 123 was previously assigned to woman 1. But data collector could assing with type same womanid 123 to waman 2. Here we would stop enter same womanid.  
Thanks,  
Narendra

---

<div class="post-metadata">

**Author:** ![elmps2018](https://odkx.b-cdn.net/user_avatar/forum.odk-x.org/elmps2018/32/105_2.png) [@elmps2018](https://forum.odk-x.org/u/elmps2018)\
**Post date:** [May 10, 2019, 9:49am UTC](https://forum.odk-x.org/t/create-unique-id-for-participant/485/9 "2019-05-10T09:49:02Z")

</div>

Hi @nsthakuri,

So you can do exactly what you want by changing the count of the fathers to be the count of women ids in your case. The structure is that async\_assign counts ids, and then there would be an error message based on the constraint if there are multiple uses of the same id.

---

<div class="post-metadata">

**Author:** ![nsthakuri](https://odkx.b-cdn.net/letter_avatar_proxy/v4/letter/n/82dd89/32.png) [@nsthakuri](https://forum.odk-x.org/u/nsthakuri)\
**Post date:** [May 10, 2019, 10:53am UTC](https://forum.odk-x.org/t/create-unique-id-for-participant/485/10 "2019-05-10T10:53:57Z")

</div>

Thanks @elmps2018,  
I’ll try.  
THanks

---

<div class="post-metadata">

**Author:** ![nsthakuri](https://odkx.b-cdn.net/letter_avatar_proxy/v4/letter/n/82dd89/32.png) [@nsthakuri](https://forum.odk-x.org/u/nsthakuri)\
**Post date:** [May 13, 2019, 10:03am UTC](https://forum.odk-x.org/t/create-unique-id-for-participant/485/11 "2019-05-13T10:03:11Z")

</div>

Hi @elmps2018,  
I tried it but not able to get it. Could you please guide that how to link js file: _customPromptTypes.js_  
Thanks

---

<div class="post-metadata">

**Author:** ![elmps2018](https://odkx.b-cdn.net/user_avatar/forum.odk-x.org/elmps2018/32/105_2.png) [@elmps2018](https://forum.odk-x.org/u/elmps2018)\
**Post date:** [May 13, 2019, 2:33pm UTC](https://forum.odk-x.org/t/create-unique-id-for-participant/485/12 "2019-05-13T14:33:51Z")

</div>

Hi @nsthakuri!

The custom prompt types file should be in the same folder as the formDef.json using it; so in ⁨app⁩ ▸ ⁨config⁩ ▸ ⁨tables⁩ ▸ ⁨questionnaire\_whatever ▸ ⁨forms⁩ folder.

Hope that helps!

---

<div class="post-metadata">

**Author:** ![nsthakuri](https://odkx.b-cdn.net/letter_avatar_proxy/v4/letter/n/82dd89/32.png) [@nsthakuri](https://forum.odk-x.org/u/nsthakuri)\
**Post date:** [May 14, 2019, 5:48am UTC](https://forum.odk-x.org/t/create-unique-id-for-participant/485/13 "2019-05-14T05:48:02Z")

</div>

Hi @elmps2018, [demogForm.xlsx](https://odkx.b-cdn.net/uploads/default/original/2X/f/f932f91904a3a1cf7d0ed9d3be9bb32aea76b357.xlsx) (20.1 KB)

I have changed woman\_id to async\_assign\_count type. Also put custom prompt type js file in same folder. Is this enough to put in the same folder? I’m still struggling with this issue. I have attached my files. Async\_assign.handlebars temple file path has been written in customPromptTypes.js file. Do we need handler file too?  
Thanks,

---

<div class="post-metadata">

**Author:** ![elmps2018](https://odkx.b-cdn.net/user_avatar/forum.odk-x.org/elmps2018/32/105_2.png) [@elmps2018](https://forum.odk-x.org/u/elmps2018)\
**Post date:** [May 14, 2019, 5:40pm UTC](https://forum.odk-x.org/t/create-unique-id-for-participant/485/14 "2019-05-14T17:40:59Z")

</div>

Hi @nsthakuri!

So I think the file is in the right place and I didn’t have any additional handler files.

One issue in your file is that your variable name, woman\_id, is circular. You need to create a variable like count\_woman\_id and async\_assign that variable, and constrain that variable to be one. Currently you are assigning the count to be woman\_id, which is not what you want.
