In ArcGIS Online in Field Calculator can I use a field value from another FeatureClass?

387
4
Jump to solution
03-17-2022 02:06 AM
Labels (2)
AngelRomoSandoval
Occasional Contributor

Hello, I hope someone could help me:

When I try to calculate a field of a Featureclass using the field value of another FeatureClass I do if it is possible to call it.

AngelRomoSandoval_0-1647507752896.png

I write this code but when I test using "return" I get nothing

 

var otherFeatureClass= FeatureSetByName($datastore,'OtherFeatureClass')

return otherFeatureClass.Name

 

 

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Honored Contributor

To build on this, specifically using the FeatureSetByPortalItem function allows you to bring in any other web layer you have access to, even those not in your Portal. No joins required, and this function should work in Pro as well.

Consider this example: I've got a test layer, and I want to update one of its fields. I have have chosen the Living Atlas's OpenStreetMap Shops, and will pipe in one of its attribute.

// get osm shops
var fs = FeatureSetByPortalItem(
    Portal('https://kendall.maps.arcgis.com/'),
    'a917a3c9e89544d9a1446251bb693bbd',
    0
)

// get first feature
var feat = First(fs)

// return `shop` attribute
return feat['shop']

jcarlson_0-1647530249890.pngjcarlson_1-1647530263764.png

And that's it! Note that I just grabbed the first feature for each, since I don't actually have a shared field between these layers, but you could easily use Filter on the featureset to get matching records based on some ID, or even use a spatial intersection to find features which intersect with yours.

- Josh Carlson
Kendall County GIS

View solution in original post

4 Replies
DanPatterson
MVP Esteemed Contributor

The tables would have to be joined.  You can't do what you want to do even in Pro or without running a full fledged script


... sort of retired...
0 Kudos
JohannesLindner
MVP Regular Contributor

The FeatureSetBy*() functions return feature sets (like the name says), which are collections of features.

You have to return the attributes of a feature, not the whole set.

var otherFeatureClass= FeatureSetByName($datastore,'OtherFeatureClass')
var firstFeature = First(otherFeatureClass)
return firstFeature.Name

Have a great day!
Johannes
jcarlson
MVP Honored Contributor

To build on this, specifically using the FeatureSetByPortalItem function allows you to bring in any other web layer you have access to, even those not in your Portal. No joins required, and this function should work in Pro as well.

Consider this example: I've got a test layer, and I want to update one of its fields. I have have chosen the Living Atlas's OpenStreetMap Shops, and will pipe in one of its attribute.

// get osm shops
var fs = FeatureSetByPortalItem(
    Portal('https://kendall.maps.arcgis.com/'),
    'a917a3c9e89544d9a1446251bb693bbd',
    0
)

// get first feature
var feat = First(fs)

// return `shop` attribute
return feat['shop']

jcarlson_0-1647530249890.pngjcarlson_1-1647530263764.png

And that's it! Note that I just grabbed the first feature for each, since I don't actually have a shared field between these layers, but you could easily use Filter on the featureset to get matching records based on some ID, or even use a spatial intersection to find features which intersect with yours.

- Josh Carlson
Kendall County GIS
SHartholt
Occasional Contributor II

I've created an expression to calculate the DueDate field of a workforce assignments feature service that is hosted on ArcGIS Online. I tested my expression using copies of the assignments feature service and a road feature class in a geodatabase on my computer and the expression functions as expected. When trying to use the expression on the assignments feature service hosted on AGOL, I receive an error stating that the Road feature service that I just published as a web layer cannot be found. Am I incorrectly referencing the feature service? What else could my issue be?

SHartholt_1-1672410368406.png

SHartholt_0-1672410149021.png

0 Kudos