Lookup() to pull values

  • Asked
  • Active
  • Viewed 1880 times
0

Hello again,

In my survey, I sample multiple individuals belonging to the same taxon. Each taxon is collected once in the field. Now, I wish to automatically associate each subsequent observation with the corresponding reference specimen.

Technically speaking, I want to pull a value (specimen_name) based on another value (taxon_name). I reckon that using idm:lookup() is the right approach here but I fail to correctly implement the code. Lookup() requires a list of values. Is it that I need to create that list beforehand?

My relevant fields: - taxon_name - specimen_name - taxon_already_sampled (yes/no) - reference_specimen

Desired output: Taxon1 is observed for the first time in the field (taxon_already_sampled = no) and is collected, hence a specimen name is attributed ("specimen1"). Subsequently, taxon1 is again encountered in the field (taxon_already_sampled = yes); in this case the individual will not be collected but instead the column reference_specimen should be auto-filled with "specimen1".

Thanks in advance for the help.

Best, Jan

1

Accepted answer

Dear Jan,
The lookup function (idm:lookup) is something you should use to fetch data from a table of the database, is not what you need in your case.
What you should do to get the value of an attribute in another row of the same table is an expression like this:

parent()/tree[taxon_name = $context/taxon_name and idm:position() != idm:position($context)] / specimen_name

With this expression you will get the value of specimen_name of another having the same taxon_name as the current row (but different position in the table, of course).

Let us know, many thanks.
Open Foris Team

The function does exactly what I wanted to do. Thank you very much!

janklein janklein

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.