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.

asked 03 Nov '16, 21:00

stonedwanderer's gravatar image

stonedwanderer
1136
accept rate: 0%


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

permanent link

answered 03 Nov '16, 21:25

Stefano%20%28OF%29's gravatar image

Stefano (OF) ♦♦
4.8k119
accept rate: 19%

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?

permanent link

answered 04 Nov '16, 06:22

liamcostello's gravatar image

liamcostello
231610
accept rate: 0%

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

permanent link

answered 04 Nov '16, 09:13

Stefano%20%28OF%29's gravatar image

Stefano (OF) ♦♦
4.8k119
accept rate: 19%

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

permanent link

answered 04 Nov '16, 09:51

stonedwanderer's gravatar image

stonedwanderer
1136
accept rate: 0%

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

permanent link

answered 04 Nov '16, 12:14

Stefano%20%28OF%29's gravatar image

Stefano (OF) ♦♦
4.8k119
accept rate: 19%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×494
×171

question asked: 03 Nov '16, 21:00

question was seen: 6,289 times

last updated: 04 Nov '16, 12:14