Accessing related attributes via relationship query

968
4
Jump to solution
02-25-2019 07:45 AM
MKF62
by
Occasional Contributor III

This is probably a pretty simple javascript syntax question but... I successfully ran a relationship query between a polygon layer and table that has multiple matching records. The problem is that I can't figure out how to access each record's attributes. The object returned from the query contains an array of features, so I figured I would just be able to index and select one single feature from the array, but it's not working out that way. I feel like it has something to do with the OBJECTID used in the relationship query, seen at the very top of the tree ("2470"):

What is the syntax for getting at these features/records?

queryableMgmtTractFL.queryRelatedFeatures(relatedQuery, function (relatedRecords) {
    console.log(relatedRecords[features[0].attributes]); //Doesn't work
});‍‍‍‍‍‍

Tried this too:

relatedRecords.features[0].attributes‍‍

The error message I get is that "features" is undefined.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
MKF62
by
Occasional Contributor III

Since the relatedRecords object can contain multiple OIDs and their related records, you have to index using the OID and then get the associated features with that OID.

relatedRecords[2470].features[0].attributes‍

View solution in original post

0 Kudos
4 Replies
MKF62
by
Occasional Contributor III

Since the relatedRecords object can contain multiple OIDs and their related records, you have to index using the OID and then get the associated features with that OID.

relatedRecords[2470].features[0].attributes‍
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Molly,

   The results of a relationship query are organized by ObjectID. So you have to do something like this:

//Where feature is the feature that you are intrested in getting the related
//records for.
var fset = relatedRecords[feature.attributes[queryableMgmtTractFL.objectIdField]];‍‍‍‍
console.log(fset.features[0].attributes);
0 Kudos
MKF62
by
Occasional Contributor III

If the relatedRecords object is already a collection of features organized by ObjectIDs, wouldn't you just need to put the OID in question as the key value for the relatedRecords object? If you had multiple object IDs queried (in my case only one will be queried at a time), you'd just need to iterate through.

var fset = relatedRecords[OID]
var feature = fset.features[0].attributes

I'm a little perplexed by the key you used in the relatedRecords object in the first code line. I would think that would come back as undefined.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Molly,

   Because a RelationshipQuery has the ability to query multiple OIDs the results are an object keyed to the objectids. So my code 

feature.attributes[queryableMgmtTractFL.objectIdField]

Is just getting the ObjectID vale for a particular feature.