Hi guys, this code works fine in AGOL Classic and shows in the popup, but no results are listed in the Map Viewer popup. (The result shows fine in Map Viewer while testing, as attached. I need this to work in the Map Viewer popup.)
What do I need to do to have the list show in the Map Viewer popup?
Solved! Go to Solution.
To post code:
(Probably) for performance reasons, fields that are not called explicitly ($feature.FieldName / $feature["FieldName"]) are not loaded. If you want to address fields dynamically, you need the Expects() function to load them first. Luckily, you don't need to type in all the fields you want to load, you can just supply a wildcard.
This is without Expects():
var fields = Schema($feature).fields
var output = []
for (var field in $feature) {
Push(output, field + ": " + $feature[field])
}
return Concatenate(output, TextFormatting.NewLine)
And with Expects(), it actually loads all the fields first, so it can show the values:
var fields = Schema($feature).fields
Expects($feature, "*")
var output = []
for (var field in $feature) {
Push(output, field + ": " + $feature[field])
}
return Concatenate(output, TextFormatting.NewLine)
Also, you don't need to get the Featureset, you can just call Schema() on $feature.
var fields = Schema($feature).fields
Expects($feature, "*")
var output = []
for (var field in $feature) {
if ($feature[field] == 'Yes') {
for (var i in fields) {
if(fields[i].name == field) {
Push(output, Replace(fields[i].alias, "_", " "))
}
}
}
}
return Concatenate(output, TextFormatting.NewLine)
To post code:
(Probably) for performance reasons, fields that are not called explicitly ($feature.FieldName / $feature["FieldName"]) are not loaded. If you want to address fields dynamically, you need the Expects() function to load them first. Luckily, you don't need to type in all the fields you want to load, you can just supply a wildcard.
This is without Expects():
var fields = Schema($feature).fields
var output = []
for (var field in $feature) {
Push(output, field + ": " + $feature[field])
}
return Concatenate(output, TextFormatting.NewLine)
And with Expects(), it actually loads all the fields first, so it can show the values:
var fields = Schema($feature).fields
Expects($feature, "*")
var output = []
for (var field in $feature) {
Push(output, field + ": " + $feature[field])
}
return Concatenate(output, TextFormatting.NewLine)
Also, you don't need to get the Featureset, you can just call Schema() on $feature.
var fields = Schema($feature).fields
Expects($feature, "*")
var output = []
for (var field in $feature) {
if ($feature[field] == 'Yes') {
for (var i in fields) {
if(fields[i].name == field) {
Push(output, Replace(fields[i].alias, "_", " "))
}
}
}
}
return Concatenate(output, TextFormatting.NewLine)
Thank you so much Johannes. That works perfectly!! 🙂
It now shows the list of Vegetation species column "Alias" names in the popup list.
Hi @JohannesLindner . Do you need a specific version of Portal for the "Expects" statement to work? Please see the issue I am having here. I'm just looking through random threads looking for answers.