Hello, I am trying to populate a field (Site_ID) in a related table (campground_evaluations) using the arcade function FeatureSetByRelationshipName. The related feature that I am trying to pull from is called MTH_Campgrounds.
In Field Maps I want to select a point (campground in this example case) and select the related table icon and enter data into the form I created for the table. Hopefully, this code will reduce the potential for error while inputting data into the table's form. The feature and table are related using Global IDs. This is where I am, but I get a Execution Error:Cannot read properties of null (reading 'toString').
var related = FeatureSetByRelationshipName($feature,'MTH_Campgrounds', ["SITE_ID"], false)
var record = First(related)
if (IsEmpty(record)){
return "No Record Found"
}
return record['SITE_ID']
Thanks in advance!
var parent_fs = FeatureSetByRelationshipName($feature, 'MTH_Campgrounds', ['SITE_ID'], true)
var parent = First(parent_fs)
if (!IsEmpty(parent)) {
return parent['Serial_Num']
} else {
return null
}
Hi Matthew, try this. I tried for so long a few weeks ago and eventually got this code to work with my dataset. I find that it helps to use the Global links to input the feature class and field and not just type it in. Hope it works for you.
Thanks for your reply!! The code still generated the error message though... I am about to resort to just making a separate table created from the relates.
Ah okay, I just realized I didn't change the "Serial_Num" to "SITE_ID" Not sure if you caught/changed that.
I did, catch that.. no go
Does the table's (campground_evaluations) field (SITE_ID) that we are trying to populate from the related feature (MTH_CAMPGROUNDS) need to be identified as a variable?
I don't think so because you are putting the arcade expression under that field on field maps. That is where you are putting it, correct?
yes that is correct
So I added brackets, and the test for this code worked!! But, when I open the map in the mobile field maps app it says calculation failed.... any ideas?
Here is the code
var parent_fs = FeatureSetByRelationshipName($feature, ['MTH_Campgrounds'], ['SITE_ID'], true)
var parent = First(parent_fs)
if (!IsEmpty(parent)) {
return parent_fs['SITE_ID']
} else {
return null
}
That was my trouble for days before I was able to get it to work. In the information I was reading.. it sounded like after $feature you had to put the relationship class name. I kept trying to do that but then randomly tried the parent class name and it worked. So I can only suggest trying different names that you used while creating the feature class?