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

asked 18 Nov '18, 15:57

Andras's gravatar image

Andras
18481952
accept rate: 0%


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

permanent link

answered 24 Nov '18, 23:02

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

Stefano (OF) ♦♦
4.7k19
accept rate: 20%

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

permanent link

answered 26 Nov '18, 11:40

Andras's gravatar image

Andras
18481952
accept rate: 0%

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

permanent link

answered 27 Nov '18, 22:33

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

Stefano (OF) ♦♦
4.7k19
accept rate: 20%

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!

permanent link

answered 28 Nov '18, 07:36

Andras's gravatar image

Andras
18481952
accept rate: 0%

edited 28 Nov '18, 09:15

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

permanent link

answered 29 Nov '18, 14:24

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

Stefano (OF) ♦♦
4.7k19
accept rate: 20%

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

permanent link

answered 30 Nov '18, 09:58

Andras's gravatar image

Andras
18481952
accept rate: 0%

edited 30 Nov '18, 13:57

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

permanent link

answered 12 Mar '21, 07:40

wexxo's gravatar image

wexxo
14511641
accept rate: 4%

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:

×493

question asked: 18 Nov '18, 15:57

question was seen: 3,967 times

last updated: 12 Mar '21, 07:40