Select to view content in your preferred language

Arcade expression returns value in popup in Map Viewer Classic but not Map Viewer

1003
4
Jump to solution
12-14-2022 09:20 AM
Labels (1)
KenBuja
MVP Esteemed Contributor

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.

species.png

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.

popup1.png

Curiously, it does show up in Map Viewer Classic

popup_classic.png

Why doesn't it show in Map Viewer?

1 Solution

Accepted Solutions
AnneFitz
Esri Regular Contributor

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!

View solution in original post

0 Kudos
4 Replies
AnneFitz
Esri Regular Contributor

Hi @KenBuja - any chance you could share the webmap? This would help us understand the issue a bit better.

0 Kudos
KenBuja
MVP Esteemed Contributor

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,', ');

withfeature.png

However, the popup does not return any values in the array

popup_withfeature.png

If I change line 6 to

Push(species,fields[i]['name']);

then I get the expected result in both the output and the popup

withoutfeature.png

popup_withoutfeature.png

 

AnneFitz
Esri Regular Contributor

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!

0 Kudos
KenBuja
MVP Esteemed Contributor

That was the answer. I keep forgetting about this function...plus it threw me that it worked properly in JS 3.x

0 Kudos