---
title: "Default value for tree species"
url: "https://openforis.support/questions/2005/default-value-for-tree-species"
tags: ["collect"]
status: "answered"
score: 1
answer_count: 7
asked: "2018-11-18T15:57:12"
last_activity: "2021-03-12T07:40:03"
source: "Open Foris Support - Q&A Forum"
license: "Copyright Open Foris, 2026. Some rights reserved under creative commons license."
---

# Default value for tree species

Asked by Andras on 2018-11-18

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


## Answer (score 1, by Stefano (OF) on 2018-11-27)

Link: https://openforis.support/questions/2005/default-value-for-tree-species/2026

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


## Answer (score 0, by Stefano (OF) on 2018-11-24)

Link: https://openforis.support/questions/2005/default-value-for-tree-species/2023

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


## Answer (score 0, by Andras on 2018-11-26)

Link: https://openforis.support/questions/2005/default-value-for-tree-species/2025

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.)?


## Answer (score 0, by Andras on 2018-11-28)

Link: https://openforis.support/questions/2005/default-value-for-tree-species/2028

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!


## Answer (score 0, by Stefano (OF) on 2018-11-29)

Link: https://openforis.support/questions/2005/default-value-for-tree-species/2035

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


## Answer (score 0, by Andras on 2018-11-30)

Link: https://openforis.support/questions/2005/default-value-for-tree-species/2038

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][1]


  [1]: http://www.openforis.org/support/upfiles/expr.jpg


## Answer (score 0, by wexxo on 2021-03-12)

Link: https://openforis.support/questions/2005/default-value-for-tree-species/3090

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
