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.
I write this code but when I test using "return" I get nothing
var otherFeatureClass= FeatureSetByName($datastore,'OtherFeatureClass')
return otherFeatureClass.Name
Solved! Go to Solution.
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']
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.
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
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
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']
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.
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?