Select to view content in your preferred language

Creating custom key with attribute rules

714
3
Jump to solution
07-21-2023 01:42 AM
PatrickLösel
Emerging Contributor

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?

Tags (1)
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

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

Have a great day!
Johannes

View solution in original post

3 Replies
JohannesLindner
MVP Frequent Contributor

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

Have a great day!
Johannes
PatrickLösel
Emerging Contributor

Hello Johannes,

thanks for the fast respond! I now tried the following expression, but it still didn't work.

2023-07-24 08_12_33-Ausdruck-Generator.png

 

0 Kudos
JohannesLindner
MVP Frequent Contributor

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

 


Have a great day!
Johannes