AnsweredAssumed Answered

New to Javascript and I need help with Query related records.

Question asked by gharlowe on Nov 26, 2014
Latest reply on Nov 26, 2014 by gharlowe

I am modifying the sample code from: and I don't understand how to configure the section:       

        function findRelatedRecords(evt) {

            var features = evt.features;

            var relatedTopsQuery = new RelationshipQuery();

            relatedTopsQuery.outFields = ["*"];

            relatedTopsQuery.relationshipId = 0;

            relatedTopsQuery.objectIds = [features[0].attributes.BUILDING_PK];

            buildingFeatureLayer.queryRelatedFeatures(relatedTopsQuery, function(relatedRecords) {

              console.log("related recs: ", relatedRecords);

              if ( ! relatedRecords.hasOwnProperty(features[0].attributes.BUILDING_PK) ) {

                console.log("No related records for Building: ", features[0].attributes.BUILDING_PK);



              var fset = relatedRecords[features[0].attributes.BUILDING_PK];

              var items =, function(feature) {

                return feature.attributes;


              //Create data object to be used in store

              var data = {

                identifier: "BUILDING_PK",  //This field needs to have unique values

                label: "Building", //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({ BUILDING_PK: "*" });



How do I indicate the related fields?


The service is restricted access and requires authentication. 

The relationships for this layer are as follows: