Thanks for your suggestion.I have combined the "Select Features" and "Query Related Records" examples for my test web application. I am a little confused in where I should put the loop featureSet.features code. Using a function calling esri.toolbars.Draw(map) to draw my selection rectangle, would I add the loop code to this function? Or add the loop code to the function calling a esri.tasks.RelationshipQuery()?Here's my code below:<script type="text/javascript">
dojo.require("esri.map");
dojo.require("esri.layers.FeatureLayer");
dojo.require("esri.tasks.query");
dojo.require("dojox.grid.DataGrid");
dojo.require("dojo.data.ItemFileReadStore");
dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.ContentPane");
var selectionToolbar, featureLayer, grid, store, selectionLayer;
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 });
map.addLayer(new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"));
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_select_box_test/MapServer", { imageParameters: imageParams });
map.addLayer(dynamicLayer);
var selectionLayer = new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([255, 255, 0, 0.5]));
selectionLayer.setOutline(new esri.symbol.SimpleLineSymbol("dashdot", new dojo.Color([255, 0, 0]), 2));
var content = "<b>Feature ID</b>: ${FeatureID}";
var infoTemplate = new esri.InfoTemplate("${FeatureID}", content);
featureLayer = new esri.layers.FeatureLayer("http://gis1ace/ArcGIS10/rest/services/MRG_select_box_test/MapServer/0", {
mode: esri.layers.FeatureLayer.MODE_SELECTION,
infoTemplate: infoTemplate,
outFields: ["*"]
});
featureLayer.setSelectionSymbol(selectionLayer);
map.addLayer(featureLayer);
dojo.connect(map, "onLoad", initSelectToolbar)
dojo.connect(featureLayer, "onSelectionComplete", findRelatedRecords);
}
function initSelectToolbar(map) {
selectionToolbar = new esri.toolbars.Draw(map);
var selectQuery = new esri.tasks.Query();
dojo.connect(selectionToolbar, "onDrawEnd", function (geometry) {
selectionToolbar.deactivate();
selectQuery.geometry = geometry;
featureLayer.selectFeatures(selectQuery, esri.layers.FeatureLayer.SELECTION_NEW);
});
}
for (var i = 0, il = featureSet.features.length; i < il; i++) {
//Get the current feature from the featureSet.
var graphic = featureSet.features;
//Relationship query
function findRelatedRecords(features) {
var relatedDocQuery = new esri.tasks.RelationshipQuery();
relatedDocQuery.outFields = ["*"];
relatedDocQuery.relationshipId = 1;
relatedDocQuery.objectIds = [features[0].attributes.OBJECTID];
featureLayer.queryRelatedFeatures(relatedDocQuery, function (relatedRecords) {
var fset = relatedRecords[features[0].attributes.OBJECTID];
var items = dojo.map(fset.features, 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 dojo.data.ItemFileReadStore({ data: data });
grid.setStore(store);
grid.setQuery({ OBJECTID: '*' });
});
}
dojo.addOnLoad(init);
</script>
Thanks for your help again!Trent