AnsweredAssumed Answered

ArcGIS JSAPI Query Related Records/Relationship Table

Question asked by geoffreywestgis on Jun 22, 2016
Latest reply on Jul 11, 2016 by geoffreywestgis

I am using this example

to develop an application which queries related features. I have two feature classes and have created a N-M relationship class. The objective is to click on an electric feeder and query the related customers. There are 26 electrical feeders and over 400 customers. My relationship class was based on the OBJECTIDs being the primary keys and the foreign keys being the "feederID" that the structures have and the that the customers are assigned to.

Ideally, I'd expect to see several customers per feeder, but based on my logic in this code sample, I am only returning the matching ObjectIDs per feeder.

What should be changed to return each customer which shares the same feeder?

function findRelatedRecords(evt) {
  var features = evt.features;
  var relatedTopsQuery = new RelationshipQuery();
  relatedTopsQuery.outFields = ["*"];
  relatedTopsQuery.relationshipId = 0;
  relatedTopsQuery.objectIds = [features[0].attributes.OBJECTID];
  wellFeatureLayer.queryRelatedFeatures(relatedTopsQuery, function(relatedRecords) {
  console.log("related recs: ", relatedRecords);
  if ( ! relatedRecords.hasOwnProperty(features[0].attributes.OBJECTID) ) {
  console.log("No related records for ObjectID: ", features[0].attributes.OBJECTID);
  var fset = relatedRecords[features[0].attributes.OBJECTID ];
  var items =, function(feature) {
  return feature.attributes;
  //Create data object to be used in store
  var data = {
  identifier: "OBJECTID", //This field needs to have unique values
  label: "OBJECTID", //Name field for display. Not pertinent to a grid but may be used elsewhere.
  items: items

  //Create data store and bind to grid.
  store = new ItemFileReadStore({ data:data });
  grid.setQuery({ OBJECTID: "*" });