Hello,
I have just started my first experiments with attribute rules.
In my organization, for house numbers, we have an attribute key for each feature, which is composed of the attributes "STRSCHL" and "HAUSNR". These are separated by an underscore. Using the attribute rules, I have managed with the following expression that this key is automatically generated and automatically adjusts when changes are made in the attributes "STRSCHL" or "HAUSNR".
$feature.STRSCHL+'_'+$feature.HAUSNR
However, there are other elements in the feature class that should not receive this key. In these, however, the underscore is always present. Using the following expression, I have now tried that the key is only assigned to features that contain the value "33100" in the attribute "OS_2".
If (Includes([$feature.OS_2],33100)) {
return
$feature.STRSCHL+'_'+$feature.HAUSNR
}
Now in the expression builder I do not get an error message about a syntax error. However, the key is not generated in practice, unlike the code above. Do I still have an error in my input or do I have to use another function?
Solved! Go to Solution.
You mixed up the arguments of Includes(). First comes the array, then the element you search for.
// array of OS_2 values for which you want to return the key
var os2_values = [33100, ]
// if the OS_2 value of the current $feature is included in that array, construct the key
if (Includes(os2_values, $feature.OS_2]) {
return $feature.STRSCHL+'_'+$feature.HAUSNR
}
// else just return what's in the field
return $feature.Key
You mixed up the arguments of Includes(). First comes the array, then the element you search for.
// array of OS_2 values for which you want to return the key
var os2_values = [33100, ]
// if the OS_2 value of the current $feature is included in that array, construct the key
if (Includes(os2_values, $feature.OS_2]) {
return $feature.STRSCHL+'_'+$feature.HAUSNR
}
// else just return what's in the field
return $feature.Key
Hello Johannes,
thanks for the fast respond! I now tried the following expression, but it still didn't work.
The second argument of Includes() has to be a single value, you're trying to input an array.
https://developers.arcgis.com/arcade/function-reference/array_functions/#includes