AnsweredAssumed Answered

Working with Related Records (query_relatedRecords) Python API

Question asked by Ben.Sperry_oxitec on Nov 5, 2018


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[k] = 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:…