Default value for tree species

  • Asked
  • Active
  • Viewed 7452 times
1

Hi,

Does default value work also for taxonomy fields?

I am trying to get the previous tree record's species and fill in the current species field:

parent()/tree[$this/parent()/tree_id - 1]/species

tree_id is a simple idm:position() field.

Thanks!

Andras

1

Accepted answer

Hi András,
Your expressions are correct and should give you the expected results (don't forget that the default value is applied only when the new row of the tree table is created).
Please try to use $context instead of $this/parent() and modify your Apply when expression into just tree_id > 1.
Also, please ensure that you are using the latest version of Collect.
Many thanks,
Open Foris Team

0

Accepted answer

Hi András,
Is the attribute tree_id a calculated attribute? If not, your expression won't work because when you create a new tree, there is no value for that attribute and the expression $this/parent()/tree_id - 1 cannot be calculated.
There is another solution that can work and uses the idm:position function. Take into account that you can use the variable $context that is equal to $this/parent().
If you only need to get the value of the previous tree, the expression can be:

parent()/tree[idm:position($context) - 1]/species

Let us know if it feets your needs.
Many thanks,
Open Foris Team

0

Accepted answer

Hi!

Sorry to be a bit vague. tree_id is calculated using idm:position() (good to know you have now $context btw. :) ). Then just for example's sake I have the default value expression as follows:

parent()/tree[$this/parent()/tree_id - 1]/species

applied when:

$context/tree_id > 1

What happens at the moment is that species for tree #2 is not filled in but both scientific and vernacular fields can be left empty (even though attribute is set to be required and relevant). I was wondering could this be due to the fact that a single taxon attribute is connected to multiple boxes (scient. and vernac.)?

0

Accepted answer

Hi,

I guess this will then fail in my case based on your response ("applied only when the new row of the tree table is created"). I would like to do this for forks (just wanted to have a simple example). Meaning that the user has to indicate first if the current tree record is a fork. If it is and it's not a first fork, species is copied from the previous tree record. Apparently this is not how it works. Or could this work in Collect Mobile?

In any case I wanted to try this with the example above, I have made all the changes you have suggested and it still doesn't work. Using Collect version 3.23.5. Can you duplicate the issue?

Thanks!

0

Accepted answer

Hi András,
What you can do in your case is to define a previous_tree_species that gives you the value of the user_specified_species of the previous tree when the expression fork is verified and a user_specified_species attribute that is relevant only when the expression not(fork) is verified. Then you can create a combination of the 2 attributes in another calculated attribute that gives you a value or the other, if the tree is a fork or not, and in analysis you can use this final attribute.
Please let us know, thanks.
Open Foris Team

0

Accepted answer

Hi,

Thanks for this work-around. My problem is still to get Collect to copy the previous species record to the following row. Below default value definition for the previous_species calculated attribute. tree_id is calculated using idm:position(). Based on the second answer I had the impression that this should work. Am I missing something?

alt text

0

Accepted answer

Hi all,

thank you for this useful expression. I have used it extensively in my survey. However, while it works fine in most cases, I do have a problem with an attribute (code) that is relevant (and visible) "only when expression is verified" related to the previous attribute. Here, the expression parent()/entity[idm:position($context)-1]/region does not work. When I remove the condition (relevant if expression), the fill with previous values works fine.

Any idea what I could do to make it work in this case?

Cheers,

Alex

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.