In Map Viewer, I had created an expression to return a list of fields. I check whether the field has the expected prefix ('MAX') and whether its value is equal to 1. I push the field alias into an array and return the return concatenated array.
var theSchema = Schema($feature);
var fields = theSchema['fields'];
var species = [];
for (var i in fields) {
if (Find('MAX', fields[i]['name']) > -1 && $feature[fields[i]['name']] == 1) {
Push(species,fields[i]['alias']);
}
}
return Concatenate(species,', ');
In the Expression editor, this runs properly and returns the expected result.
I use this expression in the Text content
There are {Sum} corals species predicted or confirmed in the {ECOREGION} ecoregion in the {PROVINCE} province: {expression/expr0}
However, this expression does not display in the Map Viewer popup.
Curiously, it does show up in Map Viewer Classic
Why doesn't it show in Map Viewer?
Solved! Go to Solution.
Hi @KenBuja - thanks for providing some more info! I think it should work if you add Expects($feature, 'MAX*') at the beginning of your expression. The Expects function makes sure you have all the fields related to your expression available on the client. By default, only the fields used to visualize your data are available. For more information, check out the documentation for the Expects function. Let me know if this works for you!
Hi @KenBuja - any chance you could share the webmap? This would help us understand the issue a bit better.
Yes I could. I've also opened a ticket (#03222527) with Esri support and we've tracked the issue down to this piece of code:
$feature[fields[i]['name']]
If I run this code in the editor, I get the expected result in the output
var theSchema = Schema($feature);
var fields = theSchema['fields'];
var species = [];
for (var i in fields) {
if (Find('MAX', fields[i]['name']) > -1){
Push(species,$feature[fields[i]['name']]);
}
}
return Concatenate(species,', ');
However, the popup does not return any values in the array
If I change line 6 to
Push(species,fields[i]['name']);
then I get the expected result in both the output and the popup
Hi @KenBuja - thanks for providing some more info! I think it should work if you add Expects($feature, 'MAX*') at the beginning of your expression. The Expects function makes sure you have all the fields related to your expression available on the client. By default, only the fields used to visualize your data are available. For more information, check out the documentation for the Expects function. Let me know if this works for you!
That was the answer. I keep forgetting about this function...plus it threw me that it worked properly in JS 3.x