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
Hi joe rodmey ,
Since you shared that code I assumed that you had the first part working already, but I see now that it is an exact copy of what I posted earlier in this thread. This mean that we should go back to the beginning and determine your exact data structure and fields that are related. In case you work with Global IDs your SQL query for the Filter will change too.
So, what is the attribute from the feature that is used to establish the relation with the related table? What is the name of the attribute it is related to in the related table?
Hi Xander Bakker
The related table was created through the Survey123 repeat type. It appears that it uses parentglobalid as the relation. This relates back to the global ID in the parent.
Hi joe rodmey ,
Would it be possible to share the survey form with me? Perhaps create a group, share your survey in that group and invite me using "xbakker@esri.co_utility_esri_co"?
To begin with I can provide screenshots/info you need
Hi Joerodney ,
OK, let's start with that.
Here is what the repeat looks like in Survey123:
And here this sample you can see the relationship field of parent global id found in the related table REST page:
Hi Joerodney
Could you try this?
// first read out the GlobalID of the Feature
var code = $feature["globalid"];
// create a sql expression to query on GlobalID
var sql = "parentglobalid = '{" + Upper(code) + "}'";
Console(sql);
// access the table
var tbl = FeatureSetByName($datastore, "Work");
// filter the table using the sql expression
var related_data = Filter(tbl, sql);
// count the resulting records
var cnt = Count(related_data);
Console(cnt);
// initiate a variable to hold the result
var result = 0;
// check if there are related records found for the current ID
if (cnt > 0) {
// loop through related records
for (var row in related_data) {
// add the value to the result
result += row.item;
}
}
// return the result
return result * 2.5;
Notice that the sql is formed differently due to the use of GlobalIDs.
Thanks so much Xander! It works now. Will continue to test but looks very promising.
Hi joe rodmey , I'm glad to hear that! Keep me posted and if you have any additional questions, please let me know.
Hi Xander Bakker
I'm also looking for a way to fill in a field (in the same related table) with "NA" if there is no value in this particular
Any ideas?
Thanks