Select to view content in your preferred language

Arcade expression containing FeatureSet not working

210
4
Jump to solution
3 weeks ago
BrianPryzby
Emerging Contributor

Hello!

I have a small Arcade expression I'd like to use in a field map. It takes a feature set from the map, which is filtered from a broader feature service, and generates a "custom" id for any newly added feature.

var POI = $feature.POI_ID
if (POI != null) {
  return POI
} else {
  return "POI " + (Count(FeatureSetByName($map, "Point of Interest"))+ 1)
}
 
This expression works as intended on ArcGIS Online in the Web Map Viewer. However, when using this expression in the field map, the feature set is not generated in relation to the features on the web map, but the entire feature service itself. So if there are five Points of Interest on the map, but 40 in the feature service, it will generate POI 41 as the POI ID. I've seen others have issues with the FeatureSetByName function in field maps, however none of the solutions seems to particularly pertain to this case. Let me know if anyone has any suggestions, or if this may just be an Esri bug.
0 Kudos
1 Solution

Accepted Solutions
DavidSolari
MVP Regular Contributor

If you wrap the feature set with a Filter and the map's definition query you can guarantee the feature count matches the map in every context.

View solution in original post

0 Kudos
4 Replies
CodyPatterson
MVP Regular Contributor

Hey @BrianPryzby 

Would there be any reason where you wouldn't be able to use GUID()?

var POI = $feature.POI_ID
if (POI != null) {
    return POI
} else {
    return "POI-" + GUID()
}

This would avoid the FeatureSetByName issue entirely, also generating a unique ID.

https://developers.arcgis.com/arcade/function-reference/text_functions/

Cody

0 Kudos
BrianPryzby
Emerging Contributor

Hi Cody, thanks for your response! This definitely would work as a way to generate a unique identifier, though I was looking for something a bit simpler. Just a sequential ID, POI 1, POI 2, etc. that would be unique to each map. There can be repeats within the broader feature layer

0 Kudos
DavidSolari
MVP Regular Contributor

If you wrap the feature set with a Filter and the map's definition query you can guarantee the feature count matches the map in every context.

0 Kudos
BrianPryzby
Emerging Contributor

Thanks David, this worked for me! It seems a bit redundant that you'd need to place a filter on a feature set, which was itself rooted in a filtered layer on a web map. But it is what it is