---
title: "How to create an auto ID?"
url: "https://openforis.support/questions/2246/how-to-create-an-auto-id"
tags: ["collect"]
status: "accepted"
score: 0
answer_count: 3
asked: "2019-04-09T09:59:07"
last_activity: "2019-04-18T11:03:29"
source: "Open Foris Support - Q&A Forum"
license: "Copyright Open Foris, 2026. Some rights reserved under creative commons license."
---

# How to create an auto ID?

Asked by Sabrina on 2019-04-09

Dear Openforis Team
In my survey new trees shall get an automatically generated ID (1, 2, 3...). For this I created a  Number Attribute field and checked "Calculated".  How do I define the Expression so that the ID always rises +1.
Thanks for your help,
Sabrina


## Accepted answer (score 2, by beka on 2019-04-09)

Link: https://openforis.support/questions/2246/how-to-create-an-auto-id/2248

Hi Sabrina,

checked as "Calculated" it is not necessary. In "Default Value" you have to write Expression

math:max(parent()/tree/tree_id)+1

where: "tree" is Entity name
       "tree_id" is Number attribute name

best regards
beka


## Answer (score 1, by Stefano (OF) on 2019-04-18)

Link: https://openforis.support/questions/2246/how-to-create-an-auto-id/2277

Dear Sabrina,  
In the default values section, you can define default values with conditions; you can define 2 items with this parameters:  

 1. Constant: 100 - Apply if: count(parent()/tree) = 1   
 2. Expression: math:max(parent()/tree/tree_num) + 1


The items defined in the default values section work like this: Collect iterates over the items defined there and when it finds an item that verifies the condition defined in the "Apply if" expression, it calculates the value to apply using the Constant field or the Expression field. If you don't specify any expression in the "Apply if" field, it means "always true" (this is why you can leave it empty only for the last item, otherwise the other items won't ever be evaluated).  

Thanks,  
Open Foris Team


## Answer (score 0, by Sabrina on 2019-04-18)

Link: https://openforis.support/questions/2246/how-to-create-an-auto-id/2275

Thanks Beka, that helped. Is it also possible that the numbering of the ID starts at 100? For example 101, 102...
