default "index(this) + 1" giving error when previously okay

  • Asked
  • Active
  • Viewed 24 times
0

Good afternoon,

Several of my surveys utilize "index(this) + 1" as a default to create a key/uid for repeated values (i.e. trees, regeneration, etc.). Since the last update, I am getting "Duplicate entity key" errors and it looks like all uid values are being populated with "1". Any ideas why this might have changed and what to do to fix it?

Thank you, Emily

0

Accepted answer

Dear Emily,
thanks for reporting this. In the latest version we changed how this is evaluated in default value expressions, to keep expressions consistent: this now always refers to the current node. In a default value expression that is the attribute itself, as it already was in the other expressions. Before, in default values, this referred to the entity containing the attribute (the tree). An attribute that is not multiple is always at position 0 in its entity, so index(this) + 1 now gives 1 for every tree, which causes the duplicate key errors.

To get the previous behaviour, change the default value expression to index($context) + 1. $context is the entity containing the attribute (the tree).

When you publish the survey, Arena asks whether to update the values in existing records. If you accept, the keys filled by the default value are recalculated, which also fixes the records entered since the update. Keys you typed by hand are kept. Note that if trees were deleted in a record, the keys of the following trees are renumbered to close the gap (e.g. 1, 3 become 1, 2). If you'd rather leave existing values untouched, publish without updating them and fix the duplicate keys by hand.

For new surveys, or if you don't need to recalculate existing data, we recommend ticking Auto incremental on the key attribute (you first need to remove its default value). Arena then numbers new trees 1, 2, 3, … and avoids duplicates even after a tree is deleted. It never changes key values already entered.

Many thanks,
The Open Foris Arena team

Wow, I love the new "auto incremental" box. Thanks so much for this quick response!

ebrodie ebrodie

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.

Tip: type a few words from the error message, or put a tag in [brackets] to look only there.

Menu

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.