Error 002717 Invalid Arcade Expression, Arcade Error:Expected feature or feature set, Script Line 2

215
3
Jump to solution
2 weeks ago
Labels (2)
JustinBernard1886
Regular Contributor

Hello,

I have a fairly simple arcade script that has been working for the past 6 years, but is now returning error, 002717.

From what I understand, this is a bug? Is there a work around for it? I pasted the code for anyone to look at. 
Basically the script will update the CH_AREA_FK with an MSLINK value from the "Character Area" feature class when a point is placed on the map.

Cheers,

Justin

var CHAreas = FeatureSetByName($datastore, 'CharacterArea', ["MSLINK"], true);
var OverlapCHAreas= Upper(DomainName(First(Intersects(CHAreas, Geometry($feature))), 'MSLINK'));
if (isEmpty($feature.CH_AREA_FK)){
return OverlapCHAreas;
}
return $feature.CH_AREA_FK

 

 

0 Kudos
1 Solution

Accepted Solutions
HaydenWelch
MVP Regular Contributor

I'd put some guard clauses in your script since line 2 has the possibility of failure since you may not have any intersecting areas:

if ($feature.CH_AREA_FK != NULL){ return $feature.CH_AREA_FK }

var CHAreas = Intersects(FeatureSetByName($datastore, 'CharacterArea', ["MSLINK"], false), $feature)

// NOTE: You should use Count(CHAreas) == 0 here if using 
// an older version of Arcade. Container checking was added 
// pretty recently
if (isEmpty(CHAreas, true)) { return $feature.CH_AREA_FK }

var OverlapCHAreas= Upper(DomainName(First(CHAreas, 'MSLINK')))

return OverlapCHAreas

 

Move the Intersect operation to the FeatureSetByName function since that allows you to skip actually loading the geometries, It also lets you then test if anything is intersecting before pulling out the first intersecting area and formatting the MSLINK field.

 

Link to the isEmpty docs to explain that note

View solution in original post

3 Replies
HaydenWelch
MVP Regular Contributor

I'd put some guard clauses in your script since line 2 has the possibility of failure since you may not have any intersecting areas:

if ($feature.CH_AREA_FK != NULL){ return $feature.CH_AREA_FK }

var CHAreas = Intersects(FeatureSetByName($datastore, 'CharacterArea', ["MSLINK"], false), $feature)

// NOTE: You should use Count(CHAreas) == 0 here if using 
// an older version of Arcade. Container checking was added 
// pretty recently
if (isEmpty(CHAreas, true)) { return $feature.CH_AREA_FK }

var OverlapCHAreas= Upper(DomainName(First(CHAreas, 'MSLINK')))

return OverlapCHAreas

 

Move the Intersect operation to the FeatureSetByName function since that allows you to skip actually loading the geometries, It also lets you then test if anything is intersecting before pulling out the first intersecting area and formatting the MSLINK field.

 

Link to the isEmpty docs to explain that note

JustinBernard1886
Regular Contributor

Great! Thanks for the help. Code worked.

RPGIS
by MVP Regular Contributor
MVP Regular Contributor

The other thing to consider is using the IIF function to determine if the record is a feature vs an empty value. Typically something like:

var CHAreas = FeatureSetByName($datastore, 'CharacterArea', ["MSLINK"], true)
var F = First(Intesects(CHAreas,Geometry($feature)))
iif( TypeOf(F) == 'Feature', Upper(DomainName(F,'MS_Link)), $feature.CH_AREA_FK )
0 Kudos