Select to view content in your preferred language

Arcade Expression Error (Buffer and Loop)

420
1
01-19-2024 10:55 AM
HeatherBrimson
New Contributor

I am doing the lab called "Building an App in ArcGIS Online to Expand Food Access" but I am stuck on the "Customize pop-ups with arcade" exercise at step 4.

What needs to be done is to create a list of retail stores that are both within a .75 mile radius and accept SNAP. This is done using two expressions. The first expression creates a radius variable using the buffer function. This is what I have, which is exactly what the lab example shows (with a different layer ID).

var retail_layer = FeatureSetById($map, "18d1d756020-layer-70")
var radius = Buffer($feature,.75,"miles")
var retail_count = Count(Intersects(retail_layer, radius))
return retail_count
 
The error comes back saying "Test execution error: Unknown Error. Verify test data."
 
I have the same issue with the second expression, which creates a loop. Again, what I have is exactly what the lab example shows (with a different layer ID):
 
var retail_layer = FeatureSetById($map, "18d1d756020-layer-70")
var radius = Buffer($feature,.75,"miles")
var nearby_stores = Intersects(retail_layer,radius)

var retail_list = ''
for(var k in nearby_stores){
retail_list += k.Store_Name + TextFormatting.NewLine
}
return retail_list
 
Any help would be greatly appreciated!
0 Kudos
1 Reply
KenBuja
MVP Esteemed Contributor

The Count function cannot take a null, so you'll have to check if the Intersects function returns a null.

var retail_layer = FeatureSetById($map, "18d1d756020-layer-70");
var radius = Buffer($feature,.75,"miles");
var result = Intersects(retail_layer, radius);
if (IsEmpty(result)) return 'No features found';
var retail_count = Count(result);
return retail_count;

The second code worked as expected in my testing (changing the layer id and the field for the retail list)

0 Kudos