Arcade Script Error: Object Not Found

375
8
04-03-2024 02:55 AM
Labels (2)
PaulGardiner
New Contributor III

Any help with this greatly appreciated.

 

I am trying to run a script using the Calculate Field tool (a script by @JohannesLindner ). 

 

// load the polygons
var polygons = FeaturesetByName($datastore, Counties)

// get the polygon that intersects the current point
var i_polygon = First(Intersects(polygons, $feature))

// return a default value if no polygon is intersecting
if(i_polygon == null) { return null }

// return the name of the Polygon
return i_polygon.COUNTY

 

This has previously worked for me but when I try it with a different polygon layer (Counties) I get an error code:  ERROR 002717: Invalid Arcade expression, Arcade error: Object not found counties, Script line: 2

 

The polygon layer is in a local folder and is definitely in the Contents.

 

Thanks.  

0 Kudos
8 Replies
jcarlson
MVP Esteemed Contributor

Since Counties is a name, it needs to be in quotes.

var polygons = FeaturesetByName($datastore, 'Counties')
- Josh Carlson
Kendall County GIS
0 Kudos
PaulGardiner
New Contributor III

Thanks for the reply. Regardless of whether I use Counties, 'Counties', or "Counties" I still get the same error message (ERROR 002717).

I've also tried changing the polygon layer name to CountyBoundary and still get the same error message.

0 Kudos
jcarlson
MVP Esteemed Contributor

So, referencing the $datastore assumes the other layer is coming from the same data source. Are these layers published in the same service, or if offline, coming from the same database?

Try referencing $map instead of the datastore.

- Josh Carlson
Kendall County GIS
0 Kudos
PaulGardiner
New Contributor III

Thanks Josh. Layers are all held locally and coming from the same folder. 

When I reference $map I get the following error message: 

ERROR 002717: Invalid Arcade expression, Arcade error: Object not found $map, Script line: 2

There have been no updates to the laptop or ArcPro since it previously worked.

0 Kudos
jcarlson
MVP Esteemed Contributor

Ah yeah, Pro doesn't like the $map object. That's for web maps only, I guess.

No updates to the software, but what about the data? I can't imagine the expression working at all with shapefiles in a folder. Were they downloaded from a web service, or copied from a database?

- Josh Carlson
Kendall County GIS
0 Kudos
PaulGardiner
New Contributor III

Weirdly enough it worked previously with shapefile data from a local folder.

Point data was exported from a SQL database. Polygon data was downloaded from a webservice. Both have been worked on locally prior to running the script.

0 Kudos
DanPatterson
MVP Esteemed Contributor

Is it a featureclass in a file geodatabase? or a shapefile in a folder?


... sort of retired...
0 Kudos
PaulGardiner
New Contributor III

It's a shapefile in a folder.

To add to the initial query... An mxd in which the script previously worked is now throwing the same error. 

0 Kudos