function getProjectReport(theFid) { var theParam = theFid.split(","); var query = new esri.tasks.Query(); query.where = "FID=" + theParam[0]; query.outFields = ["*"]; query.returnGeometry = true; var theGraphic; //Specify the appropriate point/line map service depending on what was clicked switch (theParam[1]) { case "point": var queryTask = new esri.tasks.QueryTask("URL #1"); break; case "polyline": var queryTask = new esri.tasks.QueryTask("URL #2"); break; } queryTask.execute(query,function(featureSet) { dojo.forEach(featureSet.features, function(feature) { theGraphic = feature; }); }); console.log(theGraphic.attributes.PROJECT); }
Solved! Go to Solution.
queryTask.execute(query,function(featureSet) {
dojo.forEach(featureSet.features, function(feature) {
theGraphic = feature;
});
console.log(theGraphic.attributes.PROJECT);
});
function getProjectReport(theFid) {
var theParam = theFid.split(",");
var query = new esri.tasks.Query();
query.where = "FID=" + theParam[0];
query.outFields = ["*"];
query.returnGeometry = true;
var theGraphic;
//Specify the appropriate point/line map service depending on what was clicked
switch (theParam[1]) {
case "point":
var queryTask = new esri.tasks.QueryTask("URL #1");
break;
case "polyline":
var queryTask = new esri.tasks.QueryTask("URL #2");
break;
}
console.log("Calling execute()");
queryTask.execute(query,function(featureSet) {
console.log("Task callback called");
dojo.forEach(featureSet.features, function(feature,i) {
console.log("Looping through features, current feature index =" + i + " about to set theGraphic variable");
theGraphic = feature;
console.log("Have set theGraphic variable for feature index = " + i);
});
});
console.log("Trying to log theGraphic stuff, this will fail...");
console.log(theGraphic.attributes.PROJECT);
}
Yes- I understand what Bill (and you) are saying.
What I'm not doing a good job of saying is that I want/need to access theGraphic variable AFTER the conclusion of the queryTask.Execute routine. I need to re-use the geometry and some of it's attributes for subsequent queries on additional datasets.
As my code currently exists, I can't- and I don't know what to change to get it to behave in the manner I need. I thought by declaring theGraphic as a variable at the beginning of the function it would persist and be accessible throughout the entire function but it's not (or I'm using it wrong).
function getProjectReport(theFid) {
var theParam = theFid.split(",");
var query = new esri.tasks.Query();
query.where = "FID=" + theParam[0];
query.outFields = ["*"];
query.returnGeometry = true;
var theGraphic = {attributes:{PROJECT:"nothing set yet"}};
//Specify the appropriate point/line map service depending on what was clicked
switch (theParam[1]) {
case "point":
var queryTask = new esri.tasks.QueryTask("URL #1");
break;
case "polyline":
var queryTask = new esri.tasks.QueryTask("URL #2");
break;
}
console.log("Calling execute()");
queryTask.execute(query,function(featureSet) {
console.log("Task callback called");
dojo.forEach(featureSet.features, function(feature,i) {
console.log("Looping through features, current feature index =" + i + " about to set theGraphic variable");
theGraphic = feature;
console.log("Have set theGraphic variable for feature index = " + i);
});
});
console.log("Trying to log theGraphic stuff, this will output the initial value as the callback (probably, i.e. race conditions) hasn't fired yet...");
console.log(theGraphic.attributes.PROJECT);
}
function getProjectReport(theFid) {
var theDocument, theGraphic
theGraphic = returnTipShape(theFid);
console.log(theGraphic.attributes.PROJECT);
.
.
.
}
function returnTipShape(param) {
var theParam = param.split(",");
var query = new esri.tasks.Query();
query.where = "FID=" + theParam[0];
query.outFields = ["*"];
query.returnGeometry = true;
var theShape;
//Specify the appropriate point/line map service depending on what was clicked
switch (theParam[1]) {
case "point":
var queryTask = new esri.tasks.QueryTask("http://dmc-arcgis.snoco.co.snohomish.wa.us/SnocoGISdev/rest/services/transportation/tipProjectsPoint/MapServer/0");
break;
case "polyline":
var queryTask = new esri.tasks.QueryTask("http://dmc-arcgis.snoco.co.snohomish.wa.us/SnocoGISdev/rest/services/transportation/tipProjectsLine/MapServer/0");
break;
}
dQuery = queryTask.execute(query);
var dList = new dojo.DeferredList([dQuery]);
dList.then(function(results) {
var featureSet = results[0];
dojo.forEach(featureSet.features, function(feature) {
theShape = feature;
});
});
return theShape;
}
function getProjectReport(theFid) {
var theDocument, theGraphic
returnTipShape(theFid,function(returnedShape){
console.log(theGraphic.attributes.PROJECT);
.
.
.
});
}
function returnTipShape(param,callback) {
var theParam = param.split(",");
var query = new esri.tasks.Query();
query.where = "FID=" + theParam[0];
query.outFields = ["*"];
query.returnGeometry = true;
var theShape;
//Specify the appropriate point/line map service depending on what was clicked
switch (theParam[1]) {
case "point":
var queryTask = new esri.tasks.QueryTask("http://dmc-arcgis.snoco.co.snohomish.wa.us/SnocoGISdev/rest/services/transportation/tipProjectsPoint/MapServer/0");
break;
case "polyline":
var queryTask = new esri.tasks.QueryTask("http://dmc-arcgis.snoco.co.snohomish.wa.us/SnocoGISdev/rest/services/transportation/tipProjectsLine/MapServer/0");
break;
}
dQuery = queryTask.execute(query);
var dList = new dojo.DeferredList([dQuery]);
dList.then(function(results) {
var featureSet = results[0];
dojo.forEach(featureSet.features, function(feature) {
theShape = feature;
});
callback(theShape);
});
//return theShape;
}