Select to view content in your preferred language

Another query re populating a Field Maps related table field.

145
6
a week ago
Scott_Gowan
Occasional Contributor

Greetings all,

Yet another query about populating a related table field from the parent feature layer table via a calculated expression.  I’ve followed the video below, checked it three times and worked through all ChatGPT suggestions but can’t get this to work.  It runs in the Field Maps form test and returns null but fails completely in Field Maps when adding a record to the related table.  Yes, the relationship class name is odd because it was published from a QA portal environment.  Might that be the issue?  I’ve not tried replacing the relationship class.  If I replace the relationship class will that affect the form I’ve created?  My logic says no since it’s only a connector but thought I would ask the community before hand.  Many thanks in advance for any insight.

Note: The field I'm trying to populate, “LOCATION_ID”, does exist in both tables and is not the key between tables.   (Those are Globalid in the feature layer and GUID field in the related table.)  Also, I am not creating new features, only inspecting existing locations so cannot apply an attribute rule.

Using Calculated Expressions with Related Records in ArcGIS Field Maps - YouTube

 

Expression: 

var locid = FeatureSetByRelationshipName($feature, "GISDEVREAD.DrainageClearingLocations", ['LOCATION_ID'])

var feature1 =First(locid)

if (!IsEmpty(feature1)) {

  return feature['LOCATION_ID']

} else {

  return null

}

Scott G

 

0 Kudos
6 Replies
DougBrowning
MVP Esteemed Contributor

Is that really your relationship name?  There used to be a bug where a period in the name would break it but I thought they fixed it.  It does seem like a long name though so make sure its just the name and not DBName.RelationshipName.  Check the rest page for the service to get the exact name it wants.

If that is correct then I would try writing it out using Filter(FeatureSetByName(), query) way and see if that works.  See this post  https://community.esri.com/t5/arcgis-field-maps-questions/return-a-value-depending-on-if-record-in-r...  and this one   https://community.esri.com/t5/arcgis-field-maps-questions/field-maps-featuresetbyrelationshipname-ar...

Hope that does it

0 Kudos
DavidSolari
MVP Regular Contributor

Blindly calling First on a FeatureSet causes issues during rule validation -- even if the FeatureSet has data -- so do a

if (Count(locid) == 0) return

before you grab the first feature to avoid issues.

DougBrowning
MVP Esteemed Contributor

Agreed this will get you and I see it posted a lot.  I think it is due to this blog post which is wrong IMO.  I wrote the Field Maps team directly to fix this post but got no response.

https://www.esri.com/arcgis-blog/products/field-maps/field-mobility/common-calculated-expressions-fo... 

0 Kudos
ChrisDunn1
Esri Contributor

Did you copy the arcade directly from the expression in Field Maps Designer? If so it looks like you have a typo:

var feature1 =First(locid)

return feature['LOCATION_ID'] - you're missing the "1" in the variable name for the feature.

0 Kudos
Scott_Gowan
Occasional Contributor

Thanks Chris,

Thanks for that catch.  The missing "1" was actually only a typo in this post. 

0 Kudos
Scott_Gowan
Occasional Contributor

Updated script with missing "1", same error result.

Expression: 

var locid = FeatureSetByRelationshipName($feature, "GISDEVREAD.DrainageClearingLocations", ['LOCATION_ID'])

var feature1 =First(locid)

if (!IsEmpty(feature1)) {

  return feature1['LOCATION_ID']

} else {

  return null

}

0 Kudos