I have an Arcade expression in AGOL Experience Builder where I'm trying to intersect two layers: a point layer named sites and a polygon layer named counties. I want to get the count of counties that have a site in them.
I retrieve each layer using FeatureSetByPortalItem (since apparently ExB has no profile variables like $map) and include geometry. This works fine for both layers. But the code
var result = Count(Intersects(counties, sites));
gives the error "Test execution error: Execution error - Invalid parameter. Verify test data.". What is the problem here, and is there a way to fix or get around it? Thanks!
I had a similar case with Field Maps, where geometry needed to be set to false, so this might also work for you with Experience Builder...
If you ask Field Maps to load geometry (true), it often FAILS.
This is a known Field Maps issue with FeatureSetByPortalItem.
When geometry fails to load, Field Maps gives you an empty layer → Intersects finds nothing.
If you don’t ask for geometry (false), Field Maps works.
Field Maps can fetch the geometry when needed.
So:
Why this happens:
Map Viewer runs Arcade on Esri’s servers.
Because it runs on the server, it can automatically access full geometry from any layer, even if you set:
includeGeometry = false
Intersects belongs to a group of functions that can fetch geometry later, during the calculation. Because of this, both Map Viewer and Field Maps can run:
Intersects($feature, FeatureSetByPortalItem(..., false))
without needing geometry upfront.
Thanks @EMani , but that didn't work in ExB. Same error. Full code in expression, if helpful:
// Counties
var counties = FeatureSetByPortalItem(
Portal('https://www.arcgis.com'),
'12345089c11a4913b0768381fa012345',
0,
['Name'],
false
);
// Resource sites
var sites = FeatureSetByPortalItem(
Portal('https://www.arcgis.com'),
'12345e6579894e739285f626c7e12345',
1,
['Name'],
false
);
return Count(Intersects(counties, sites));
You might need to replace the last line with:
return Count(Intersects($feature, sites));
This is what worked for me:
Thanks again. Unfortunately, the error popping up with that is that it doesn't recognize $feature. There are no profile variables in the ExB Arcade profile. Documentation does say it includes the Geometry function bundle, which includes Intersects. It's a mystery!
@ZenMasterZeke, I assume you're using Arcade via the Data tab (not seeing FeatureSetByPortalItem as a usable function when e.g., adding a text widget, connecting it to data, etc.).
If so, I think the problem is that you're not returning a featureset? If you just add your data to a featureset (even though it's a featureset of 1 record), Experience Builder can then work with it.
This is messy but works. It counts the number of counties in Michigan that have at least one site on the National Register of Historic Places (76):
var counties = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), '14c5450526a8430298b2fa74da12c2f4', 0, ['NAME'], true)
var miCounties = Filter(counties, 'STATE_FIPS = \'26\'')
var sites = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), 'd1073c2945cb4c6793136f51a97bdd8d', 0, ['RESNAME'], true)
var newDict = {fields: [
{name: 'Count', alias: 'Count of Counties with Sites', type: 'esriFieldTypeInteger'}
],
geometryType: '',
features: []
}
var countyCount = 0
for (var i in miCounties){
var siteCount = Count(Intersects(i, sites))
if (siteCount > 0){
countyCount++
}
}
Push(newDict['features'], {attributes: {Count: countyCount}})
var fs = FeatureSet(newDict)
return fs