Working with Related Records (query_relatedRecords) Python API

11-05-2018 05:43 AM
Occasional Contributor


I need to be able to summarize nested related records. I have been through the documentation and sample notebooks but have been unable to connect the dots on this. I would appreciate any help in understanding the process.

Here is where I am now:

# get the feature layer collection from AGOL
feature_layer_collection = gis.content.get('bf7307237621413fb692f2f1a6f26211')

# get the feature layer of interest
feature_layer = feature_layer_collection.layers[0]

# get the related tables of interest
feature_table1 = feature_layer_collection.tables[0]
feature_table2 = feature_layer_collection.tables[1]

# query the related records from feature_table

related_table1 = feature_layer.query_related_records(object_ids="2", relationship_id="1", out_fields="*")
related_table2 = feature_table1.query_related_records(object_ids='2', relationship_id="2", out_fields="*")

# Look at what's inside the result


Type: dict String form: {'fields': [{'name': 'objectid', 'type': 'esriFieldTypeOID',
    'alias': 'ObjectID', 'sqlType': 'sql <...> 'sqlTypeOther',
'length': 128, 'domain': None, 'defaultValue': None}], 'relatedRecordGroups': []} Length: 2 Docstring: dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)

There is nothing in the 'relatedRecordsGroups', how do I access the values in the related table?

How do I summarize those values?

Thank you for any help.

Here is the URL for the feature service I am using in this example: 

0 Kudos
1 Reply
Occasional Contributor

Crickets for a year and a half... Anyone at Esri monitoring? 

I am trying to figure out how to create the relationships in the first place. Is this done in Pro and published to AGOL? Or is this the "Join Features" option in AGOL's analysis tools? 

0 Kudos