Arcade script works in 'Run' with no errors, but doesn't show any results.

659
4
Jump to solution
03-13-2023 10:14 AM
TSWCD_GIS
New Contributor III

I am using Map Viewer (not classic) to create a map using feature layers hosted on our AGOL account. I've made sure they are in spatial reference 3857. The Arcade script below is supposed to show the City Name from the city boundary layer that intersects with the tax lot I click on. I have this as an Arcade expression in the tax lot pop up. When I click on "Run" in the Arcade script window it gives me a valid response. I get no errors about the code. When I try to use it in the map though, the pop up shows a little spinning wheel for half a second and then is blank. I've researched code examples for this and no matter what I do, the results never display in the pop up. I'm obviously missing something here, can anyone explain what I am doing wrong?

 

var city_fields = ['CITYNAME']

var fac = FeatureSetByName($map, "City Boundaries", city_fields)

var intfac = First(Intersects($feature, fac))

If(IsEmpty(intfac)){

    return 'Jurisdiction: Unincorporated Washington County'

} Else {

  return city_fields

  }
0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

Your last line is wrong. You're returning city_fields, which is an Array: ['CITYNAME']

When you test the expression, it will successfully return that array (or more probably the default value). I would argue that it is not a valid response, though, as you want the actual field value...

In the popup, it tries to return the array, but it's only allowed to display a string, so it displays nothing.

 

var fac = FeatureSetByName($map, "City Boundaries", ["CITYNAME"])
var intfac = First(Intersects($feature, fac))
If(IsEmpty(intfac)){
    return 'Jurisdiction: Unincorporated Washington County'
} 
return intfac.CITYNAME

 


Have a great day!
Johannes

View solution in original post

0 Kudos
4 Replies
JohannesLindner
MVP Frequent Contributor

Your last line is wrong. You're returning city_fields, which is an Array: ['CITYNAME']

When you test the expression, it will successfully return that array (or more probably the default value). I would argue that it is not a valid response, though, as you want the actual field value...

In the popup, it tries to return the array, but it's only allowed to display a string, so it displays nothing.

 

var fac = FeatureSetByName($map, "City Boundaries", ["CITYNAME"])
var intfac = First(Intersects($feature, fac))
If(IsEmpty(intfac)){
    return 'Jurisdiction: Unincorporated Washington County'
} 
return intfac.CITYNAME

 


Have a great day!
Johannes
0 Kudos
TSWCD_GIS
New Contributor III

Thank you Johannes for that explanation!

Along with this, I also found that I can only get text responses to show up in my pop ups if I do the following code for the final 'return' (I can't figure out why, I see very few examples with this):

 

 

return { 
	type : 'text', 
	text : intfac.CITYNAME 
}

 

0 Kudos
JohannesLindner
MVP Frequent Contributor

Seems like you're working with an Arcade Element.

These are slightly different from "normal" Arcade expressions. An Expression in a popup behaves somewhat like a field. You can show it in the field list, and you can use it's return value in text elements. But an expression can only return one value and it has to be a basic data type (string, integer, float, date).

Elements can do more advanced stuff like returning multiple values, displaying charts, or evaluating HTML. But to be able to do that, the popup has to know what you're returning, that's why you have to specify that with the dictionary.

You see few examples of Arcade Elements because they're still quite new (Arcade 1.16, which corresponds to ArcGIS Pro 2.9 and ArcGIS Enterprise 11.0). Most people still work with Arcade Expressions.

 

The docs for the Arcade Element (the docs call it Popup Element, but I believe in the Map Viewer its actually Arcade Element) is here: https://developers.arcgis.com/arcade/profiles/popup-element/

And here are some examples of return dictionaries: https://developers.arcgis.com/web-map-specification/objects/popupElement/


Have a great day!
Johannes
0 Kudos
TSWCD_GIS
New Contributor III

Thanks so much Johannes for that breakdown, it has made this much easier 😀

0 Kudos