Select to view content in your preferred language

Attribute Rule to automatically populate two fields based on another

266
1
02-22-2025 05:18 AM
EngineeringLockport
Occasional Contributor

Hello,

I am a complete novice when it comes to attribute rules.  

I have a long list of values of common names.  I would like to automatically populate the genus and species fields based on the common name.  I am not sure if this is a constraint rule or a validation rule and am unsure of the proper syntax to use. 

I have looked at some examples on this blog, but what I want to do does not involve calculations or geometry. 

It would basically be a "If $feature.commonname = (a particular value) then genus = "value" and species = "value".  I have all of the values input into my domains, but would prefer a common name populate those fields rather than selecting from possible values.

Any help/guidance would be greatly appreciated.

 

Thanks!

0 Kudos
1 Reply
ZachBodenner
MVP Regular Contributor

It does sound like you are looking for a calculation though. Are you planning on having the species and the genus get entered whenever a new feature is created? In that case, you'd want to set up a calculation rule using basically the syntax you provided above. When you're looking at the attribute rule, don't set the field to be calculated (leave it blank) and then you'd want something like this:

Var c = $feature.commonname

// Decode matches two values, one from the common name variable and then another for the genus or species name to be populated in those fields.
Var g = decode(c, ‘CommonName1’,’GenusName1’, ‘CommonName2’,’GenusName2’,etc)
Var s = decode(c, ‘CommonName1’,’SpeciesName1’, ‘CommonName2’,’SpeciesName2’,etc)

return{
 'result':{
  'Attributes':{
   'Genus':g,  
   'Species':s
  }
 }
}
Happy mapping,
- Zach
0 Kudos