---
title: "How to validate attibutes calculated from expression?"
url: "https://openforis.support/questions/510/how-to-validate-attibutes-calculated-from-expression"
tags: ["collect"]
status: "answered"
score: 0
answer_count: 3
asked: "2016-04-21T12:05:34"
last_activity: "2016-04-22T15:59:42"
source: "Open Foris Support - Q&A Forum"
license: "Copyright Open Foris, 2026. Some rights reserved under creative commons license."
---

# How to validate attibutes calculated from expression?

Asked by hfuchs on 2016-04-21

OF Collect version 3.9.13:  
I created a new unique ID calculated from an expression from the attribute tree ID and stem ID 
and I'd like to use the new calculated ID for checking the uniqueness during data entry.   
The options "Is key?" and "Strict" in Survey Designer are disabled for calculated attributes. How can I prevent duplicates during data entry and cleansing? Kind regards.


## Answer (score 0, by Stefano (OF) on 2016-04-22)

Link: https://openforis.support/questions/510/how-to-validate-attibutes-calculated-from-expression/514

Hi,  
Nowadays you cannot define a calculated attribute as identifier of an entity.  

You can define **both** `tree_id` and `stem_id` as the key identifiers for the `tree` entity.

Please try it and let us know.  
Thanks,  
Open Foris Team


## Answer (score 0, by hfuchs on 2016-04-22)

Link: https://openforis.support/questions/510/how-to-validate-attibutes-calculated-from-expression/517

Dear ricci and Open Foris Team,  
the first solution was already smart but this one is very elegant and works perfectly. Grazie mille!


## Answer (score 0, by Stefano (OF) on 2016-04-22)

Link: https://openforis.support/questions/510/how-to-validate-attibutes-calculated-from-expression/518

Hi,  
If you need to define a uniqueness check for one (or more) "primary key" attribute, just define it as Key.  
If you already defined an attribute as the (primary) key attribute and you want to check the uniqueness of another attribute, you can create a new **Uniqueness** check for that attribute and write an expression that will return the list of values that must be unique (e.g. suppose that you want to assign a `tree_name` to every tree and this name must be unique, you can define a Uniqueness check with an expression like:  `parent()/tree/tree_name`. The check will verify that the value you insert in `tree_name` is unique considering all the tree entities.  

If you want to check the uniqueness of more than one attribute, for example `attribute1` and `attribute2` you cannot use the Uniqueness check (nowadays...) but you have to define a **Custom** check using an expression like this:  

`count(parent()/tree[attribute1 = $this/parent()/attribute1 and attribute2 = $this/parent()/attribute2]) = 1`

This expression looks a bit tricky but it's just saying that the number of trees having attribute1 and attribute2 equal to the `current` one must be equal to 1.

Thanks a lot,  
Open Foris Team
