Hello all,
I'm trying to use Field Maps to create a form for field data collection.
We've got areas that need to be surveyed which I've got as a pre-existing polygon layer.
I've set up the field map to have the survey Location name (which is prepopulated) and then survey date and surveyor's name to be collected when they arrive.
I've been trying to use an arcade expression to pass the surveyor name and survey date to another (point) layer using intersects / within, but am having no luck.
Using this code I've at least seen the field-headings in the "test" section:
var Mines_Info = FeatureSetByName($map, "Mine_Locations")
var MInfo = Intersects($feature, Mines_Info)
return MInfo
But I'm at a loss as to how to pass the information I want through. I either get a "Cannot access property of a null object" error in the arcade window, or a "Failed to calculate" error on the Field Maps app.
Thankyou!
Solved! Go to Solution.
Hi David,
The issue is likely because you are returning a feature set rather than a specific feature even though there is an intersect. You also need to tell the Arcade editor what field value you want to return.
var Mines_Info = FeatureSetByName($map, "Mine_Locations", [‘the field name you want to return’])
MInfo= first(intersects($feature, Mines_Info)
Return Minfo[‘the field name you want to return’]
Another option is you could use the following Arcade functions to return the user name and date.
Date: Now() this will returns the current date and time in the local time of the client.
User Name: GetUser($layer).fullName
We have a blog here with the most common expressions used in Field Maps in case this helps for future expressions.
Hi David,
The issue is likely because you are returning a feature set rather than a specific feature even though there is an intersect. You also need to tell the Arcade editor what field value you want to return.
var Mines_Info = FeatureSetByName($map, "Mine_Locations", [‘the field name you want to return’])
MInfo= first(intersects($feature, Mines_Info)
Return Minfo[‘the field name you want to return’]
Another option is you could use the following Arcade functions to return the user name and date.
Date: Now() this will returns the current date and time in the local time of the client.
User Name: GetUser($layer).fullName
We have a blog here with the most common expressions used in Field Maps in case this helps for future expressions.
"I've been trying to use an arcade expression to pass the surveyor name and survey date to another (point) layer using intersects / within, but am having no luck. "
I'm a bit murky on what you are trying two accomplish. It sounds like you are trying to change another features attributes, rather than the feature in your current edit session. If so, be aware that you can only change the values of the current feature. You can retrieve data from another layer, but only for the purpose of manipulating you current form or feature.
Also be aware that the Intersects function has to forms. It can return Boolean (true/false) if comparing two geometries or a featureSet if comparing a featureSet to some inputGeometry.
You may also want to test that Mines_Info is not empty before trying to do the intersect as that may explain your failed to calculate or null object error as well.
As Sarah mentions above, you can't return a featureSet. The Form Calculation Arcade Profile only supports the return types of Number, Date, or Text. https://developers.arcgis.com/arcade/profiles/form-calculation/
Nope - im also getting the same kind of errors
the return does not like: feature['value']
it also does not like First(Intersects(
further: it is giving bad / inconsistent results between AGOL,
field maps in online mode, and field maps offline mode
I am doing this very same thing. I am intersecting a point with an existing parcel polygon layer and trying to return the Parcel ID of the parcel polygon I have the code written as you have above. It is returning the Parcel ID of the very first polygon from from the parcel layer with the objectID = 1. My guess is due to returning the feature set instead of the feature, but not sure how to fix this.
var parcel = FeatureSetByName($map, 'Parcel Lines2', ['ParcelID']);
var parcInter = First(Intersects($feature, parcel));
return parcInter['ParcelID'];
Any help would be greatly appreciated!
This eventually worked for me, but with the following modification:
var MInfo= first(intersects(Mines_Info, $feature)
I am having an issue with this also. The code below works great in ArcPro 3.2.1 but the code doesn't go with the feature layer when published to AGOL and copy/paste the same code to the features in agol does nothing at all. This is capturing the Meadow name from a Meadows layer and populating the Plantspecies Meadow field with the meadow name.
var fsMeadows = FeatureSetByName($datastore, "Meadows", ["Meadow"])
var fsMeadowsIntersect = Intersects(fsMeadows, $feature)
var Meadows = First(fsMeadowsIntersect)
if (Meadows == null) return {"errorMessage": "Meadow not found"}
return Meadows.Meadow
Instructions say this should work in agol but it doesn't! Ref this discussion:
Your if statement might be the issue there if you are still having issues. It should go more like this:
if (Meadows == null) {
return "Meadow not found"
}
else return fsMeadows
I'm curious can you perform an intersect to identify the largest intersecting piece? For example, if I'm trying to populate a field from an underlying soils layer to a forest stand layer. The forest stand may intersect several different soils, but how can I get an attribute from the soil that encompasses the largest acreage of intersection? "First" won't always get the right one.
Thanks Luke, I'll try it for sure, I see the difference in form.
Soils are a particularly odd beast where each soils poly is it's own mix of soils. I'm facing the same dilemma in an experience builder project. I feel the need for an intermediary step that creates a temporary layer with the predominance calculated then grab the info from that temporary layer but honestly I haven't made progress on that side project as yet.