Autopopulate Child Field Based on Parent Layer in a Relationship Class

484
3
Jump to solution
02-10-2023 07:09 AM
JanicePulver
New Contributor II

I was able to use the expression below to autopopulate the ditch ID based off of the parent layer when the user adds a new maintenance log. Since updating that layer, by adding two new fields, it doesn't want to work now. 

// Get the feature set for the ditches
var ditches = FeatureSetByRelationshipName($feature, 'DitchGroundProof',['SegmentNumber'], true)

// Get the first ditch (should only be one)
var ditch = First(ditches)

// If there was a ditch, return the number of it,
// Otherwise, return null
if (!IsEmpty(ditch)) {
return ditch['SegmentNumber']
} else {
return null
}

 

I have read that FeatureSetByRelationshipName doesn't want to work sometimes, but I can't figure out the work around. 

0 Kudos
1 Solution

Accepted Solutions
JanicePulver
New Contributor II

I previously did look into FeatureSetByName and relating the GUID and GlobalID's possibly as a workaround, but didn't get anywhere. I went back and did it again after your comment and found an expression that works! I found it on this previous post https://community.esri.com/t5/arcgis-field-maps-questions/featureset-not-working-offline-in-field-ma...

var ref_guid= upper ($feature.GUID)

if(IsEmpty(ref_guid)) {
return null
}

var wells_fs=FeatureSetByName($map,"Ditch Maintenance")
var wells_filter = Filter(wells_fs, `GlobalID = '${ref_guid}'`)
var well = First(wells_filter)

if (IsEmpty(well)){
return null
}
return well.TempDitchNum

Thanks for this little extra push I needed to solve my problem!

View solution in original post

0 Kudos
3 Replies
ZhongmingAn
New Contributor III

FeatureSetByName maybe?

I was having problems accessing related tables using FeatureSetByRelationshipName as well, but it never worked from the start. FeatureSetByName somehow worked.

0 Kudos
JanicePulver
New Contributor II

I previously did look into FeatureSetByName and relating the GUID and GlobalID's possibly as a workaround, but didn't get anywhere. I went back and did it again after your comment and found an expression that works! I found it on this previous post https://community.esri.com/t5/arcgis-field-maps-questions/featureset-not-working-offline-in-field-ma...

var ref_guid= upper ($feature.GUID)

if(IsEmpty(ref_guid)) {
return null
}

var wells_fs=FeatureSetByName($map,"Ditch Maintenance")
var wells_filter = Filter(wells_fs, `GlobalID = '${ref_guid}'`)
var well = First(wells_filter)

if (IsEmpty(well)){
return null
}
return well.TempDitchNum

Thanks for this little extra push I needed to solve my problem!

0 Kudos
ZhongmingAn
New Contributor III

Glad you figured it out!

0 Kudos