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

8506
27
Jump to solution
12-22-2023 05:14 AM
Labels (2)
KGalluccio
Regular Contributor

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
27 Replies
AdamAull
Emerging Contributor
Hello Nathan,

Unfortunately I haven't been able to find an Arcade solution to this issue yet. The workaround I have is using Python run on a workstation as a task to pull the address from the source feature class and populate the field in the related table. Python could work in a Notebook, but I'm not willing to spend the credits each time the task runs.

-Adam
0 Kudos
MonmouthNJGIS
Occasional Contributor

Thanks for sharing this! I am trying to use this in my Organization's Field Mowing Operation. We have an Open Fields layer with a related Mowing table (1:M) based of the Field LINKID (' Park_Area'+ '-' + 'Filed ID'). I'd like to be able to pull the attributes for Park Area and Field ID automatically into the new related record.

I suppose I have two questions:

A. If I understand correctly, this is possible?

B. I am a little lost as to where this arcade expression is placed as I don't see an option to add Arcade Scripts to the related table.

 

Thank you for any help!

0 Kudos
MonmouthNJGIS
Occasional Contributor

Thanks for sharing this! I am trying to use this in my Organization's Field Mowing Operation. We have an Open Fields layer with a related Mowing table (1:M) based of the Field LINKID (' Park_Area'+ '-' + 'Filed ID'). I'd like to be able to pull the attributes for Park Area and Field ID automatically into the new related record.

I suppose I have two questions:

A. If I understand correctly, this is possible?

B. I am a little lost as to where this arcade expression is placed as I don't see an option to add Arcade Scripts to the related table.

 

Thank you for any help!

0 Kudos
AdamAull
Emerging Contributor

The Arcade expression(s) for the related table are placed in the Forms. You create an editing form in Map Viewer as you would for a feature layer. Add the fields you want to calculate with Arcade, then create the expression.

I've added a 4 step illustration.

0 Kudos
sofoo
by
Frequent Contributor

This did not work for me.  None of the posted solutions did.  One of them worked in AGOL but not in the Field Maps App...

I was able to get mine working with this though:

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

// Get the feature set for the hydrants
var hydrants = FeatureSetByRelationshipName($feature, 'wHydrant', ['facilityid'], false)

// Get the first hydrant (should only be one)
var hydrant = First(hydrants)

// If there was a hydrant, return the facilityid of it,
// Otherwise, return null
if (!IsEmpty(hydrant)) {
    return hydrant['facilityid']
} else {
    return null
}

 

0 Kudos
LukeRoyle
Emerging Contributor

Are you able to provide yours as an example? I'm confused as to where this goes and to where I should put feature class, standalone table and the relationship in the code in order to get it working. Also in which attribute are you putting the expression?

0 Kudos
AmandaHoffman1
New Contributor

I have been trying to add an asset ID to my related table from the parent feature. I tried some of the other solutions listed and still have not been able to get the field to populate. 

My goal is to have the Asset ID auto populate in the Field Maps form when a new inspection is being added to the point. I wrote this expression based on this the esri example. 

AmandaHoffman1_0-1751051867261.png

 

0 Kudos
AdamAull
Emerging Contributor

Hi Amanda.

The issue you are having caused me to attempt this on my own. I created a feature class with related table, published the service to my Portal and created the Arcade expression. I was able to successfully populate the related table pointID field from the origin table using the code below. 

I added the FeatureSetByRelationshipName on line 2 directly from the Profile Variables list to ensure the correct spelling of the backwards relate name.

-Adam

Image3.png

// Get the feature set for the hydrants
var hydrants = FeatureSetByRelationshipName($feature, "To_TestPoint", ['pointID'], true)

// Get the first hydrant (should only be one)
var hydrant = First(hydrants)

// If there was a hydrant, return the facilityid of it,
// Otherwise, return null
if (!IsEmpty(hydrant)) {
    return hydrant['pointID']
} else {
    return null
}

 

0 Kudos
AdamAull
Emerging Contributor

Continued testing, and found that FieldMaps indeed does not add the pointID to the related table. Appears that FieldMaps will not honor the Arcade expression. The image shows “Failed to calculate” on the field. I believe this to be a bug in FieldMaps.

-Adam

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