QGIS Form – Setting Relation Value in QGIS Form

attribute-tableqgisvaluerelation

I'm building a form to collect observation data of species. I have a layer called "observation" (point) with a field called "observer", it is the name of who sees the species. Secondly, I have a table with all the employees of the company.

In my form, I use a relation value for the field "observer" with my table, so that I have a drop-down menu with all the employees. It works perfectly.

The problem is in my layer "observation", I have many other observers, and they disappeared when I used the relation value, cause they are not in the list.

How can I have a drop-down menu with my employees, for new inputs through the form, but still let me have other "old" records with different employees?

Best Answer

Keep the "old" field with the old observers, then create a new field with value relation that you use for new oberservs: those you take with value relation from the table. So you have a clean dataset and don't have to mix old and new observers with the risk of altering data.

You can define a constraint in the "new" field so that if the "old" field already contains a name, it should stay empty.

To combine both old and new observer values, create a 3rd field as virtual filed that dynamically updates and that combines both fields, like:

if (length ("name_old") > 0, "name_old",  represent_value ("name_new"))

This field is what you're looking for as it combines bot manually entered values as well as the names from the value relation.

enter image description here

Related Question