Auto populate Related table from Parent table using Arcade in AGOL?

2882
15
Jump to solution
12-22-2023 05:14 AM
Labels (2)
KGalluccio
New Contributor II

Is is possible to auto populate fields in a related table from the selected record in the parent table using Arcade in AGOL? 

I have a AGOL web map that includes one hosted feature layer with a related table with a one to many relationship.  The number of features in the feature layer is static.  Using forms, the map allows the user to select a feature and edit it's attributes, including adding records to the related table.  

The work process is that the current attributes of the selected feature need to be added as a new record in the related table, and then updated with new information.

When the user selects a feature to edit, then clicks to add a record to the related table, I would like the fields to auto populated with the selected features attributes.  

Is this possible?

Tags (2)
0 Kudos
2 Solutions

Accepted Solutions
marksm_macomb
Occasional Contributor

I've been implementing this arcade script in the smart forms for my related tables to auto populate the parent ID field in the related table, but you could use it for any additional fields as well. So this script would be applied to a calculated expression on the field you are trying to populate (my relationship class is based on GlobalIDs):

var parent_id = $feature.ParentGUID

Var related_Features = FeatureSetById($datastore, "layerid")

Var parent_Feature = First(Filter(related_Features, 'GlobalID = @parent_id'))

if(parent_Feature == null){
return
}
else {
return parent_Feature.FACILITYID
}

 

View solution in original post

AdminNCCMA
New Contributor III

Hi Mark,

I'm new to expressions in AGOL.

I have a related dataset and table published, the relationship is based on GlobalIDs. I'd like to populate in the related table a field named 'Bore_ID' from the field in my spatial data named 'Bore_ID_' and I am struggling to figure it out following your method. Any help would be VERY much appreciated.

 

View solution in original post

0 Kudos
15 Replies
marksm_macomb
Occasional Contributor

I've been implementing this arcade script in the smart forms for my related tables to auto populate the parent ID field in the related table, but you could use it for any additional fields as well. So this script would be applied to a calculated expression on the field you are trying to populate (my relationship class is based on GlobalIDs):

var parent_id = $feature.ParentGUID

Var related_Features = FeatureSetById($datastore, "layerid")

Var parent_Feature = First(Filter(related_Features, 'GlobalID = @parent_id'))

if(parent_Feature == null){
return
}
else {
return parent_Feature.FACILITYID
}

 

KGalluccio
New Contributor II

Thank you.  This worked well.

0 Kudos
Laura
by MVP Regular Contributor
MVP Regular Contributor

I am looking to populate the gravesiteid field from the parent into the gravesite id field in the related table, but running into issues

Laura_0-1704983378862.png

Could anyone write out what goes where?

 

0 Kudos
KGalluccio
New Contributor II

I would get the same error because I was not referencing the correct layer_id from the map.

Are you sure your layer_id is "gravesiteid"?  From my limited experience it is usually not that descriptive.

For ex. a layer_id in one of my maps for a Road layer named "Roads" is "18cf513418f-layer-3". 

The only way I have found so far to get a layer_id without using code is to use ArcGIS Assistant to view the JSON of the web map.

 
0 Kudos
Laura
by MVP Regular Contributor
MVP Regular Contributor

I tried putting some #s in, but still get an error. I am very new to this so I guess I'm confused on what it is asking for. 

Laura_0-1704986177510.png

Update:

This is what ended up working for me

Laura_0-1707228995908.png

 

 

0 Kudos
KGalluccio
New Contributor II

Issue might be in your third line for the filter.  You have it filtering to 'gravesiteid = @gravesiteID'

I think it should be 'gravesiteid=' + gravesiteID.

Here is the code I am using that is working.  In the featuresetbyid I am adding a third parameter to just grab the specific field.

var join_ID = $feature.ID

var fs_prevprojyear = FeatureSetById($map, "18cf513418f-layer-3", ['Project_Ye'])

var filter_relate_feature = First(Filter(fs_prevprojyear, 'ID=' + join_ID))

return filter_relate_feature.Project_Ye

0 Kudos
marksm_macomb
Occasional Contributor

@Laura  I think the problem might be in your FeatureSetById expression as well, specifically with the layer id. You can auto-populate the FeatureSetById expression by using the profile variables in the arcade editor by going here:

marksm_macomb_0-1705067242706.png

Then choose the arrow next to the layer you are interested in and it will give you the expression with the correct layer id already filled out.

Another way to check your layer ID is to go to the overview page for your layer and look at the URL:

marksm_macomb_1-1705069304620.png

The blue highlighted section is the ITEM Id, and the green highlighted part is the LAYER Id.

Hope this helps!

 

0 Kudos
AdminNCCMA
New Contributor III

Hi Mark,

I'm new to expressions in AGOL.

I have a related dataset and table published, the relationship is based on GlobalIDs. I'd like to populate in the related table a field named 'Bore_ID' from the field in my spatial data named 'Bore_ID_' and I am struggling to figure it out following your method. Any help would be VERY much appreciated.

 

0 Kudos
ChristopherCounsell
MVP Regular Contributor

No this is not directly possible. Here are your options:

  • User does second edit on point feature
  • Automated process to check for new related records, update parent, then flag related table field as processed
  • Set up the edit to use Survey123 Inbox. Custom url scheme, limit repeat count, calculations. User adds and updates directly

I think option 2 is best. Use ArcGIS Notebooks to run a python script every 15min. Cleanest data control without exposing the direct disability of the parent point to end users.

0 Kudos