Select to view content in your preferred language

Arcade return not showing in popup

816
3
Jump to solution
05-11-2023 10:17 PM
Labels (2)
TimWarfe_MSC
Occasional Contributor

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?

var features = FeatureSetByName($datastore, 'Vegetation', ['*'], false);
var aDict = Schema(features);
var aArray = aDict['fields'];
var output;
for (var i in $feature) {
    if ($feature[i] == 'Yes') {
        for (var j in aArray) {
            var dict = aArray[j];
            if (dict['name'] == i) {
                output += dict['alias'] + TextFormatting.NewLine
            }
        }
    }
};
return replace(output, '_', ' ');
0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

To post code:

JohannesLindner_0-1677736512957.png

JohannesLindner_1-1677736529803.png

 

 

(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)

JohannesLindner_0-1683881638884.png

 

 

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)

JohannesLindner_1-1683881709330.png

 

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)

Have a great day!
Johannes

View solution in original post

3 Replies
JohannesLindner
MVP Frequent Contributor

To post code:

JohannesLindner_0-1677736512957.png

JohannesLindner_1-1677736529803.png

 

 

(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)

JohannesLindner_0-1683881638884.png

 

 

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)

JohannesLindner_1-1683881709330.png

 

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)

Have a great day!
Johannes
TimWarfe_MSC
Occasional Contributor

Thank you so much Johannes.  That works perfectly!!  🙂   

It now shows the list of Vegetation species column "Alias" names in the popup list.  

0 Kudos
BrianBulla
Honored Contributor

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.

https://community.esri.com/t5/arcgis-online-questions/arcade-not-working-in-pop-up/m-p/1338803#M5513...

 

0 Kudos