Set a field automatically based on the value of an enumeration field

Hi,
I have an enumeration field “Country”. The “values” of this enumeration are the country codes and the display names are the country names.
Now I want to add a second field “CountryCode”, which is set automatically based on the field “Country”. So the enumeration values from the field “Country” should be displayed in the field “CountryCode”.
Is that possible and what would be the best implementation? Should “CountryCode” be also an enumeration or rather a string field?

P.S. This is the same problem as described in this topic. Maybe now there is a way to do it? How to assign an enum value code to a string field using a computation?

Hi @maria-wintry-ice,

You still get the same warning from the Kernel if you try to write an enumeration value into either a string or an enumeration field but I’ve got a little workaround for you. The pictures are from the 2023.06 release but this works in 2023.02 too :slight_smile:

If you write your country codes into the enumeration as a category, you can then use these in the computation

The category is referenced using [country → code] see here.

This results in the code being shown as desired.

Thanks for the workaround @malcolm-silver-ice! Does it also work the same way, if I use the enumeration “Value” als category? So, adjusting your Screenshots it would look like this:


In my case, I would like to display “de” in the last screenshot and not “1”.

Changing the category name from “code” to “value” will not have the effect that I think you were looking for.

You can write the same information in the values and the new category “code”. I’ve shown this in the new screenshots. You have to write them in by hand but it’s okay if they match the values.


Ok. I wanted to avoid to have to write them by hand, but this helps anyway. Thank you!