Select to view content in your preferred language

featuresetByName help in Field Maps

407
3
Jump to solution
02-05-2025 07:33 AM
CJCowardin
Emerging Contributor

I'm trying to use an example I found to work with my data. I have a Sign layer that will be collected with Field Maps.  In that layer is a field called Parent_Asset_ID.  I have another layer called County_Parks. Inside County_Parks is a field called Asset_ID. I need the Parent_Asset_ID to fill in with the Asset_ID from the County_Parks layer. This is what I did:

// Create a feature set using the 'County_Parks' layer in the map
var County_Parks = featuresetByName($map, 'County_Parks', ['Parent_Asset_ID'])

// Intersect the current location with the County_Parks and
// get the first park
var County_Parks = First(Intersects($feature, County_Parks))

// If the current location does intersect a feature,
// return the name of the County_Park. Otherwise, return null
if (!IsEmpty(County_Parks)) {
    return County_Parks['Parent_Asset_ID']
} else {
    return null
}
0 Kudos
1 Solution

Accepted Solutions
DougBrowning
MVP Esteemed Contributor

What is going wrong?  Is it a crash?

I do know that if you try to run First on an empty set then it will crash.  So you need to check the intersect for IsEmpty before you try First.

So more like this

var County_Parks = featuresetByName($map'County_Parks', ['Parent_Asset_ID'])

 

// Intersect the current location with the County_Parks and
 
var County_Parks = Intersects($featureCounty_Parks)
// If the current location does intersect a feature,
// return the name of the County_Park. Otherwise, return null
if (!IsEmpty(County_Parks)) {
    return First(County_Parks)['Parent_Asset_ID']
else {
    return null
}

View solution in original post

0 Kudos
3 Replies
DougBrowning
MVP Esteemed Contributor

What is going wrong?  Is it a crash?

I do know that if you try to run First on an empty set then it will crash.  So you need to check the intersect for IsEmpty before you try First.

So more like this

var County_Parks = featuresetByName($map'County_Parks', ['Parent_Asset_ID'])

 

// Intersect the current location with the County_Parks and
 
var County_Parks = Intersects($featureCounty_Parks)
// If the current location does intersect a feature,
// return the name of the County_Park. Otherwise, return null
if (!IsEmpty(County_Parks)) {
    return First(County_Parks)['Parent_Asset_ID']
else {
    return null
}
0 Kudos
CJCowardin
Emerging Contributor

When I test it in the expression window, it comes back with "Test execution error: Execution error - Cannot access property of null object. Verify test data."

On the map, when I start editing, it just says Failed to calculate value

0 Kudos
CJCowardin
Emerging Contributor

I got it to work! Thanks.