How to create an auto ID?

  • Asked
  • Active
  • Viewed 4452 times
0

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

2

Accepted answer

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

1

Accepted answer

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

0

Accepted answer

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

Your answer

Markdown text. Shortcuts: Ctrl+B bold, Ctrl+I italic, Ctrl+K link, Ctrl+E code, Ctrl+Shift+V paste as plain text. Tab indents list items and code; press Escape, then Tab, to leave the text box.

Insert an image

Say what the image shows, for people who can't see it.

Keyboard shortcuts

Anywhere

?
Show this list
/
Search
g h
Go to the home page
g q
Go to the questions
g t
Go to the tags
g u
Go to the users
a
Ask a question

Lists of questions

j k
Next or previous question
Enter
Open the question

Question pages

j k
Next or previous post

Shortcuts never apply while you type in a text field. Members can turn them off in their preferences.