Trying to populate fields by intersect, from another layer in the fieldmap

1403
5
Jump to solution
01-24-2023 06:59 PM
DavidCarroll94
New Contributor

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!

0 Kudos
1 Solution

Accepted Solutions
SarahSaint-Ruth
Esri Contributor

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.

 

View solution in original post

5 Replies
SarahSaint-Ruth
Esri Contributor

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.

 

JustinReynolds
Occasional Contributor III

"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/

 

- Justin Reynolds, PE
0 Kudos
NevilleWilson_Everick
New Contributor III

Nope - im also getting the same kind of errors

the return does not like: feature['value']

it also does not like First(Intersects(

NevilleWilson_Everick_0-1698110099447.png

 

NevilleWilson_Everick_1-1698110258111.png

 

NevilleWilson_Everick_2-1698110328363.png

 

NevilleWilson_Everick_3-1698110361205.pngNevilleWilson_Everick_4-1698110455161.png

 

 

further: it is giving bad / inconsistent results between AGOL, 

field maps in online mode, and field maps offline mode

 

NevilleWilson_Everick_5-1698110551916.png

 

NevilleWilson_Everick_6-1698111106435.png

 

 

 

 

 

0 Kudos
DarrylAlbert
New Contributor III

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!

D_AnneHammond
New Contributor III

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:

https://community.esri.com/t5/arcgis-online-ideas/support-for-attribute-rules-in-arcgis-online/idi-p...

0 Kudos