relationshipQuery not returning multiple related overlapping features

01-25-2011 06:44 AM
Occasional Contributor
New question, but semi related to an earlier thread...

After learning that the selection tool was selecting multiple/overlapping features, and returning the multiple non-related values to the dataGrid, it looks like the relationshipQuery task is not returning the related data correctly.  What is happening is that with the relationshipQuery task is only returning one set of related data to the dataGrid when selecting more than one feature.  The task returns correctly a single feature with multiple related records from the SDE table.  If I select two features only one of those features, and related tabular records, are returned to the dataGrid.  Not both features and their associated related records.  This is what I am trying to figure out.

Dissecting the relationshipQuery JS 2.1 example from ESRI, it seems that the code should be returning multiple values because of the event.  From what I've read, the event creates a new array of elements based on the return value from the callback function.  So shouldn't this be returning the multiple selected features from the relationshipQuery task?  Or should there be a loop farther up in the realationshipQuery task?  Here's the code below...

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <meta http-equiv="X-UA-Compatible" content="IE=7" />
  <!--The viewport meta tag is used to improve the presentation and behavior of the samples
  on iOS devices-->
  <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
  <title>Test - Selection Box</title>
    <link rel="stylesheet" type="text/css" href="" />
    <link rel="stylesheet" type="text/css" href=""/>
    <link rel="stylesheet" type="text/css" href=""/>
    <style type="text/css">
      .soria .dojoxGridHeader .dojoxGridCell   {
        color:peru !important;

    <script type="text/javascript">
        djConfig = {
            parseOnLoad: true
    <script type="text/javascript" src=""></script>

    <script type="text/javascript">
        dojo.require("dijit.dijit"); // optimize: load dijit layer

        var map, toolbar, featureLayer, grid;
        function init() {

            var initialExtent = new esri.geometry.Extent({ "xmin": -107.75, "ymin": 30, "xmax": -105, "ymax": 40, "spatialReference": { "wkid": 4269} });
            var map = new esri.Map("map", { extent: esri.geometry.geographicToWebMercator(initialExtent), slider: true, nav: true });

            dojo.connect(map, 'onLoad', function (map) {
                //initialize the toolbar
                toolBar = new esri.toolbars.Draw(map);
                dojo.connect(toolBar, "onDrawEnd", onDrawEnd);
                dojo.connect(dijit.byId('map'), 'resize', resizeMap);

            var basemap = new esri.layers.ArcGISTiledMapServiceLayer("");

            var imageParams = new esri.layers.ImageParameters();
            imageParams.layerIds = [0];
            imageParams.layerOption = esri.layers.ImageParameters.LAYER_OPTION_SHOW;
            var dynamicLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://gis1ace/ArcGIS10/rest/services/MRG_Point/MapServer", { imageParameters: imageParams });

            featureLayer = new esri.layers.FeatureLayer("http://gis1ace/ArcGIS10/rest/services/MRG_Point/MapServer/0", {
                mode: esri.layers.FeatureLayer.MODE_SELECTION,
                outFields: ["*"]

            featureLayer.setSelectionSymbol(new esri.symbol.SimpleMarkerSymbol().setSize(8).setColor(new dojo.Color([160, 214, 238])));        

            /*var selectionSymbol = new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([255, 255, 0, 0.5]));
            selectionSymbol.setOutline(new esri.symbol.SimpleLineSymbol("dashdot", new dojo.Color([255, 0, 0]), 2));


            dojo.connect(featureLayer, "onSelectionComplete", findRelatedRecords);


        // select features using toolbar and build query
        function onDrawEnd(extent) {
            //select features within the draw extent
            var query = new esri.tasks.Query();
            query.geometry = extent;
            //execute query
            featureLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW);

            //Relationship query
            function findRelatedRecords(records) {                
                    var relatedDocQuery = new esri.tasks.RelationshipQuery();
                    relatedDocQuery.outFields = ["*"];
                    relatedDocQuery.relationshipId = 1;
                    relatedDocQuery.objectIds = [records[0].attributes.OBJECTID];
                    featureLayer.queryRelatedFeatures(relatedDocQuery, function (relatedRecords) {
                        var fset = relatedRecords[records[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{ data: data });
                        grid.setQuery({ OBJECTID: '*' });

         function resizeMap() {
             //resize the map when the browser resizes
             var resizeTimer;
             resizeTimer = setTimeout(function () {
             }, 500);


<body class="soria">
  <div id="mainWindow" dojotype="dijit.layout.BorderContainer" design="headline" gutters="true" style="width:600px; height:700px;">
    <div dojotype="dijit.layout.ContentPane" region="top">
      <button dojoType="dijit.form.Button" onClick="toolBar.activate(esri.toolbars.Draw.EXTENT);">Select Layer</button>
      <button dojoType="dijit.form.Button" onClick="toolBar.deactivate();featureLayer.clearSelection();">Clear Selection</button><br />
  <div id="map" region="center" dojotype="dijit.layout.ContentPane" style="border:1px solid #000;"></div>
  <div dojotype="dijit.layout.ContentPane" region="bottom" style="height:150px; width="100%;"">
        <table dojoType="dojox.grid.DataGrid" jsid="grid" id="grid" rowSelector="20px" selectionMode="none">
              <th field="FeatureID">Feature ID</th>
              <th field="Title" width="25%">Title</th>
              <th field="FileName" width="10%">File Name</th>
              <th field="Description" width="100%">Description</th>

Thanks for your help and let me know if I've been unclear with my question.

0 Kudos
1 Reply
Occasional Contributor II
I thought, too, that the relationshipQuery should be going through multiple related overlapping features. After picking through the code, I found that it only does a relationship query on the first feature in the list of selected features.

                    relatedDocQuery.objectIds = [records[0].attributes.OBJECTID]; // only pulling first element from records array
                    featureLayer.queryRelatedFeatures(relatedDocQuery, function (relatedRecords) {
                        var fset = relatedRecords[records[0].attributes.OBJECTID]; // again pulling first element from records array
                        var items =, function (feature) {                            
                            return feature.attributes;

To get all the objectIds, you would do something more like this.

relatedDocQuery.objectIds =, function (record) { return record.attributes.OBJECTID; });

I'll have to come back later and add code to list all the result. in the items.
0 Kudos