---
title: "Collect: how to set auto increment on key?"
url: "https://openforis.support/questions/856/collect-how-to-set-auto-increment-on-key"
tags: ["collect", "collectmobile"]
status: "answered"
score: 0
answer_count: 5
asked: "2016-11-03T21:00:47"
last_activity: "2016-11-04T12:14:33"
source: "Open Foris Support - Q&A Forum"
license: "Copyright Open Foris, 2026. Some rights reserved under creative commons license."
---

# Collect: how to set auto increment on key?

Asked by stonedwanderer on 2016-11-03

When creating a survey on Collect, it is useful (and, most of the times, required) to add a unique identifier (key) for your records. This key is generally a 'number' attribute. However, reading the manual it looks like it's not possible to set this field as an AUTO INCREMENT field (like one would do in a typical database like MySQL).
How can I set my key field to be managed as an AUTO INCREMENT field (value generated automatically by adding 1 to the corresponding value in the previous record) and avoid to input manually a new value each time I add a record?
This would save a lot of time and also prevent errors in my records (it could happen to input the same value more than once, especially if you add lots of records in a short time and/or you're in the field using Collect Mobile).

Thanks in advance to anyone who could point me to the right direction.


## Answer (score 0, by Stefano (OF) on 2016-11-03)

Link: https://openforis.support/questions/856/collect-how-to-set-auto-increment-on-key/857

Hi,  
This is not the first time we receive the same requirement...  
First of all you have to consider that even if you use a sequential number as id, this will be unique only in the same device (tablet or PC...).  Instead what you can use as key for your record is the combination of a Text attribute that contains some kind of random unique value and a Date attribute with the date of recording; for the Text attribute you can use in the default value expression the function **util:uuid()** (this function generates a *UUID - Universal Unique Identifier* text value).  
As default value for the Date attribute you can use **idm:currentDate()**.  
The combination of the 2 will be unique even considering a data collection process that involves different devices.  
Let us know if this solution can fit your needs.  
Thanks,  
Open Foris Team


## Answer (score 0, by liamcostello on 2016-11-04)

Link: https://openforis.support/questions/856/collect-how-to-set-auto-increment-on-key/859

Good question. 

In addition can you clarify: if this field (UUID+Date) is set as a calculated field and Not Shown In Entry Form, will the date recalculate each time the attribute is opened? For example if it is opened the following day?


## Answer (score 0, by Stefano (OF) on 2016-11-04)

Link: https://openforis.support/questions/856/collect-how-to-set-auto-increment-on-key/860

Sure, if it is a *calculated* attribute it will always be recalculated.  
Instead you have to use a default value applied to an attribute that can be edited by the user.  
Starting from version 3.12 of Collect there will be the possibility to make the attributes read-only so the user won't be able to change the default value applied.  
Thanks,  
Open Foris Team


## Answer (score 0, by stonedwanderer on 2016-11-04)

Link: https://openforis.support/questions/856/collect-how-to-set-auto-increment-on-key/861

Thank you guys for your assistance. I will try to implement your solution. I think it could be a nice workaround.

The only difference with what I wanted to do is that an auto-generated 'number' attribute would also help you in counting how many observations you have made. How can I do this without an AUTO INCREMENT field?

Thanks again.

Luca


## Answer (score 0, by Stefano (OF) on 2016-11-04)

Link: https://openforis.support/questions/856/collect-how-to-set-auto-increment-on-key/864

Hi Luca,  
adding the auto increment field is a bit complex now.  
If you are just interested on counting how many observations you have made, we can add a field in the record list of Collect Mobile showing how many records have been collected.  
As I was saying, please also consider that the auto increment field will be unique only for a single device.  
Thanks,  
Open Foris Team
