How do you reference another field from a related table in Arcade?

18451
61
02-26-2019 06:19 AM
deleted-user-TRj-mR_qEmwV
New Contributor III

Through a Web Map in ArcGIS Online, I'm creating a field in Feature #1 and Feature #1 is related to Feature #2.  Is there a way to get the specific values in Feature #2 that are related via for an Arcade expression in Feature #1?

It's a 1 to many relate and related through a Text ID Field that they both have. 
EDIT: I think it has something to do with FeatureSetBy functions

0 Kudos
61 Replies
XanderBakker
Esri Esteemed Contributor

Hi joe rodmey , 

Do you want to write that value ("NA") to your attribute table or you just want the pop-up to show "NA" when there is no value?

0 Kudos
joerodmey
MVP Alum

Xander Bakker‌ I would like to write the value of "NA" to my attribute table in AGOL

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi joe rodmey ,

In that case you can use a Field Calculation to do this. 

When(IsEmpty(feature$.YourFieldName), "NA", feature$.YourFieldName);

The IsEmpty function will check for Null values or empty strings and when it finds such a value it will return "NA". 

Since with the Field Calculation you potentially overwrite existing data, you can best add another field to test the expression.

0 Kudos
joerodmey
MVP Alum

Would this automatically occur when new related data rolls in? The reason I need this is that Collector is automatically adding in blank records and I need a way to handle these.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Joerodney ,

Unfortunately not. This can be achieved with ArcGIS Enterprise and Attribute rules or not allowing the users to generate empty fields in Collector (field value required and use default NA and/or a domain).

0 Kudos
joerodmey
MVP Alum

How can I make certain fields required in Collector or default to NA?

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Joerodney ,

Good question. There is a thread from almost a year ago mentioning that the default values are not taken correctly in Collector. Not sure if that is still the case. The thread I mentioned offers a alternative way to have the default values working correctly: Default Values in Collector 

0 Kudos
joerodmey
MVP Alum

I had a look but unsure if this will work as my feature service was created in Survey123

0 Kudos
joerodmey
MVP Alum

HI Xander Bakker

How can I take the code you provided earlier and return the value of zero only if the related record doesn't have a value entered?

Thanks

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi joe rodmey ,

If this value should appear in the pop-up, you can do this without a problem. If this should be written to the hosted service you can also, but you need to use a Field Calculation (and repeat this when the data is updated. The code would be more similar to the one posted before (using the FeatureSetByName and Filter option). Based on the count you would return the value.

0 Kudos