I am trying to create a custom fields list in a pop up. I want to hide some values, including any fields that are null or empty. I have seen other posts doing this using arcade blocks in the pop up, I used those as an example.
When I run code before saving it, it works as expected. However, when I save it and open a pop up I always get "No attributes to display" indicating that there are no fields to display that meet the criteria. If I add a fields list with all of the fields visible to the pop up, the Arcade block works as expected. It seems like you have to use the field in the pop up before you can reference it with Arcade, but that doesn't really make sense. Any ideas of how I can fix this or what is going on? Code is below - disclaimer, the code was generated with ChatGPT.
var fieldInfos = []
var attributes = {}
// list of exact field names to exclude (case-insensitive)
var excludeFields = [
"objectid","globalid","parentglobalid","parentrowid",
"creator","creationdate","editor","editdate",
"created_user","created_date","last_edited_user","last_edited_date",
"issue_comment", "issue_resolution"
]
// poi_ fields to display
var keepPOIFields = [
"poi_reviewer_comments"
]
for (var att in $feature) {
var attLower = Lower(att)
// exclude exact matches
if (IndexOf(excludeFields, attLower) > -1) continue
// handle poi_ logic
var isPOI = Left(attLower, 4) == "poi_"
var isAllowedPOI = IndexOf(keepPOIFields, attLower) > -1
if (isPOI && !isAllowedPOI) continue
var val = $feature[att]
if (!IsEmpty(val)) {
Push(fieldInfos, { fieldName: att })
attributes[att] = $feature[att]
}
}
if (Count(fieldInfos) == 0) {
return {
type: "text",
text: "No attributes to display"
}
}
return {
type: 'fields',
title: 'POI Details from Inspection',
fieldInfos,
attributes
}
Solved! Go to Solution.
What happens when you put the Expects function at the top of the script?
That worked! I used Expects($feature, '*'). Thanks for the tip, it makes sense after reading the documentation on the function.