Hello again,

In my survey, I repeatedly sample the same taxa. Hence, in order not to enter all information over and over again, I would like Open Foris to recognise whether a taxon had already been sampled within the sampling unit.

So far, I unsuccessfully tried with the following code which is to be added into the "only when expression is verified" field: true(idm:contains(parent()/a_in_ind/taxon,taxon))

Am I getting it wrong?

Thanks for the help in advance, Jan

asked 16 Mar '22, 10:42

janklein's gravatar image

janklein
216
accept rate: 0%


Dear Jan,
First of all, when you are working with complex expressions using a composite attribute, like taxon, that has multiple fields, it would be better to extract the code value into a calculated attribute, that you could call species_code, with an expression like this:

species/@code

Then you could verify, into another calculated attribute, hidden in data entry, that the same species has been already sampled in another calculated attribute (e.g. species_already_sampled) with an expression like this:

count(parent()/individuals[species_code = $context/species_code]) > 1

that means that there is at least one row in your table having the same species code of the current row. The expression $context/species_code is a shortcut for $this/parent()/species_code.
After that, you can use the species_already_sampled value into a Relevant when condition, to make a field relevant and trigger the apply of the default value expression on it.

Let us know if this will help you to solve your problem.
Many thanks,
Open Foris Team

permanent link

answered 16 Mar '22, 22:24

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

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

Dear Stefano,

thank you very much for your quick reply. The workaround works fine.

Just one last question: How can I use species_already_sampled as a condition? It seems like it outputs a boolean (true/false). When trying to code "true(species_already_sampled)", OF runs into an error. I also tried "species_already_sampled = 'true'", but the code doesn't work.

Thanks again,

Jan

permanent link

answered 17 Mar '22, 09:49

janklein's gravatar image

janklein
216
accept rate: 0%

Dear Jan,
You can use write just species_already_sampled in the Relevant when expression, to make an attribute relevant in that case and apply a default value on it, for example. You don't need to cast the result of the expression into a boolean value, since it's already boolean.
Many thanks,
Open Foris Team

permanent link

answered 17 Mar '22, 14:36

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

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

Hello again,

After having implemented the workaround described above it appears to be working for the first but not for the following subplot entities.

Each plot is subdivided into 8 entities (sub-plots). Each sub-plot contains the following three attributes relevant to the question: - taxon: taxa from species list - taxon.code: taxon/@code as integer - taxon.already.sampled: text attribute calculated based on the following expression:

string(count(parent()/subplot1[taxon.code = $context/taxon.code]) > 1)

In the first entity (subplot 1), the field taxon.already.sampled correctly recognises when a taxon has already been sampled (true) and when it has not yet been sampled (false).

The problem evolves in the second (and the following) subplot. We would like OF to recognise if a taxon had already been sampled in any subplot (not only the current one). Thus, I added a second term to incorporate the former entities in the attribute taxon.already.sampled, resulting in the following expression:

string(count(parent()/subplot1[taxon.code = $context/taxon.code]) > 1) or string(count(parent()/subplot2[taxon.code = $context/taxon.code]) > 1)

This code, though, does not work correctly. The field taxon.already.sampled remains ‘true’ for all newly added taxa, regardless of whether or not they had already been sampled within the current or a former subplot. The validation rules based on this attribute are thus not correctly warning the user if a specimen needs to be collected or not.

It seems that the expression in subplot2 fails to extract from subplot1.

Which expression should I use in the taxon.already.sampled field to check for correspondences within all subplot entities?

Thank you very much in advance, Jan

permanent link

answered 28 Mar '23, 12:24

janklein's gravatar image

janklein
216
accept rate: 0%

edited 28 Mar '23, 12:35

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

question asked: 16 Mar '22, 10:42

question was seen: 1,186 times

last updated: 28 Mar '23, 12:35