Calculate ID field in Related Table using ID field in Parent Table

534
3
06-28-2023 01:26 PM
Labels (2)
LeilaJackson1
Occasional Contributor III

Hi -

I have a feature service with a polygon layer (SNP_PROJECT) and a related point layer (SNP_PHASE), they are related (SNP_PROJECT_PHASE) using globalID and GUID. I would like to field calculate the ID field in the related point layer using the ID from the parent polygon layer using an arcade (or python)  expression in ArcGIS Pro. This is what I have, but it is not working. I would appreciate any suggestions. Thanks!

var related = FeaturesetByRelationshipName($feature, "SNP_PROJECT_PHASE")
       return related.PROJECTID

0 Kudos
3 Replies
JoshuaSharp-Heward
Occasional Contributor III

Hi Laila,

Why are you wanting to field calculate the ID? Is it for when you're creating a new feature in the related table? Because if so you shouldn't have to be scripting that via arcade or Python, if you're creating the related record in Field Maps or via the "Add new to relationship" (https://pro.arcgis.com/en/pro-app/latest/help/editing/edit-feature-relationships.htm) in ArcGIS Pro it should be automatically populating the GUID field.

0 Kudos
LeilaJackson1
Occasional Contributor III

@JoshuaSharp-Heward 

Thanks for your questions. I am using Survey123 which requires a GlobalID-GUID relationship. In addition, My ID field in the main layer must be calculated on the backend after the Survey123 form is submitted as it includes a sequential number that must be determined by referencing the data in the feature layer. Once that ID is created, I can calculate the ID in the related table which is used in a second ID for the related table. These are IDs used to reference projects so we need them in addition to the Global ID, and they have been in use prior to the use of the Survey123 form.

0 Kudos
JoshuaSharp-Heward
Occasional Contributor III

Ahh okay that makes sense! FeatureSetByRelationshipName will return a feature set, and in your above code you're not pulling out a record from it (which will only be 1 record), so wrapping the FeatureSetByRelationship in the First() function should fix that. That being said it isn't running on my machine, possibly due to me having an older version of ArcGIS Pro? Worth a go anyway. Also what back end process are you using to calculate the ProjectID on the parent table? It might be easier to include this process as a part of that to reduce the amount of manual work. A solid alternative is also using a Joined Hosted Feature Layer view to bring together all of the parent and child info into a flat table, which would mean you wouldn't have to calculate it into the table for the related record, depending on what you want to use it for.

0 Kudos