I'm getting a ReferenceError "results is not defined" on the queryTask.execute:
//first, check to see if a workplan boundary exists
if (this.workplanId) {
var queryUrl = "https://somewebsite/someagssite/rest/services/folder/servicename/FeatureServer/0"
var queryTask = new QueryTask(queryUrl);
var query = new Query();
query.returnGeometry = true;
query.where = "workplanId ='" + this.workplanId + "'";
debugger;
queryTask.execute(query).then(function (results) {
this.workplanCheckValue = results.features.length;
});
}
console.log("workplanCheck value is: ", this.workplanCheckValue)
I need to set this.workplanCheckValue to the number of features returned from the queryTask.
Any assistance appreciated!
Solved! Go to Solution.
James,
It is likely something simple But I do not see it in the code you are sharing. You do not see any errors in the console when you try and run the code, beside the reference error?
Sorry, that was my fault again. I was stepping thru the debugger. Your code works perfectly of course!
Thanks again for your assist and lesson.
The reason why I thought it wasn't properly set is because I have this queryTask in the Startup: function() and it seems to not fire (deferred?) in the order I am expected. That is it will initially hit eh queryTask but then not actually execute and simply continue on thru until the startup finished then it will .exectute. For example, the first console print is:
console.log("2 workplanCheck value is: ", this.workplanCheckValue)
Then this:
console.log("1 workplanCheck value is: ", this.workplanCheckValue)
So what happens is my condition statements get evaluated first before I can set the this.workplanCheckValue variable to the result of the queryTask.
constructor: function (args) {
lang.mixin(this, args);
window.map = this.map;
},
startup: function () {
////first, check to see if a workplan boundary exists
if (this.workplanId) {
var queryUrl = "https://somesite/rest/services/myservice/FeatureServer/0";
var queryTask = new QueryTask(queryUrl);
var query = new Query();
query.returnGeometry = true;
query.outFields = ['*']
query.where = "workplanId ='" + this.workplanId + "'";
debugger;
queryTask.execute(query, lang.hitch(this, function (result) {
debugger;
this.workplanCheckValue = result.features.length;
console.log("1 workplanCheck value is: ", this.workplanCheckValue)
}));
}
console.log("2 workplanCheck value is: ", this.workplanCheckValue)
//debugger;
if (this.editLayer == 'WP' && this.reviewStatus == 'Draft Mode' && this.workplanCheckValue > 0 ) {
this.beginWork_Workplan_ExistingBoundary();
}
else if (this.editLayer == 'WP' && this.reviewStatus == 'Draft Mode' && this.workplanCheckValue < 1) {
this.beginWork_Workplan_NoExistingBoundary();
}
},