I am making a relationship query with multiple Objects IDs and receiving multiple related record groups. I can access the Object IDs for the related records but I don't know how to access the actual records for that ID. Is there an example on how to access related record groups and its records?
Solved! Go to Solution.
Using the executeRelationShipQuery on a queryTask an object with the related record groups is returned. The OIDs can be used as a key to then get to the object Ids (or whatever is needed) within the related record groups. This is how I did it:
var queryTask = new QueryTask("http//...");
var query = new RelationshipQuery(); query.outfields
;
query.objectids [queryIds]; // multiple Ids e.g. [105,106,233]
query.relationshipId = 2;
queryTask.executeRelationshipQuery(query, function(realtedRecordsGroups)){
allRelatedRecordsIds = [];
for(var obid in relatedRecordsGroups){
allRelatedRecordsGroups.push(results.features.attributes.OBJECTID);
}
});
Thanks Robert for taking a look at it. I'm actually using executeRelationshipQuery on a queryTask but even then is the example really feeding multiple ObjectIDs into the query? I'm looking at line 151: relatedQuery.objectIds = [graphicAttributes.objectid];
Anika,
No that sample is just querying one ObjectId. But Querying multiple is supported you just use the OID i=as the array key when going through the returned results (as the sample does show).
Robert,
Sure, I can query for multiple but I need an example how I can actually access the result. I am able to get the keys but not the actual related record group records. So I was hoping to see if it is done somewhere to get a better understanding.
Anika,
The sample I provided show how to get the results from the related query based on the OID. So if you have queried for multiple OIDs then you just use one of those OIDs to get the related records from the results.
incidentLayer.queryRelatedFeatures(relatedQuery, function(relatedRecords) {
var fset = relatedRecords[graphicAttributes.objectid];
So in line 2 above the results for one specific OID is returned based on using that OID as the key in the relatedRecords array from the relates query. The fset is an array of feature that are related to the OID.
Using the executeRelationShipQuery on a queryTask an object with the related record groups is returned. The OIDs can be used as a key to then get to the object Ids (or whatever is needed) within the related record groups. This is how I did it:
var queryTask = new QueryTask("http//...");
var query = new RelationshipQuery(); query.outfields
;
query.objectids [queryIds]; // multiple Ids e.g. [105,106,233]
query.relationshipId = 2;
queryTask.executeRelationshipQuery(query, function(realtedRecordsGroups)){
allRelatedRecordsIds = [];
for(var obid in relatedRecordsGroups){
allRelatedRecordsGroups.push(results.features.attributes.OBJECTID);
}
});