Select to view content in your preferred language

Return value from queryTask.execute()

1430
5
02-07-2013 01:56 AM
Udaya_BhaskerCheerala
Emerging Contributor
Hi All
I have written the below code to get the feature count. I have declared m_featCount as global variable, and assigning value to it in getStateCount(featureSet) function and calling this function in twnqueryTask.execute(). In getStateCount() funciton, m_featCount value showing perfectly. When I try to access the variable m_featCount in another function MyLogic() or GetState(evt), I am getting null value. I can write my logic in getStateCount() function, but I need the value of m_featCount variable throughout the application.
Please help me how resolve this issue.

var m_featCount;
function GetState(evt) {
var twnqueryTask = new esri.tasks.QueryTask("http://myserver/WSIPL/rest/services/myservice/MapServer/3");
var twnquery = new esri.tasks.Query();
twnquery.returnGeometry = true;
twnquery.outFields = ["LNDKEY", "SECTIONKEY"];
twnquery.geometry = evt.mapPoint;
twnqueryTask.execute(twnquery, getStateCount);
}
function getStateCount(featureSet) {
m_featCount= featureSet.features.length;
}


Function MyLogic()
{
if(m_featCount>0){
// I will write my logic here but in this function Iam getting featCount = 'undefined'
}
else
{
// I will write my logic here
}
}



Thanks,
Uday
0 Kudos
5 Replies
SimonLeo
Deactivated User
did you call MyLogic after getStateCount() executed?
also is that a typo 'Function MyLogic()' instead 'function MyLogic()'?
0 Kudos
Udaya_BhaskerCheerala
Emerging Contributor
Yes I call MyLogic() after getStateCount(). And eventhough I change 'Function MyLogic()' to 'function MyLogic()' I am getting null value.

Thanks,
Uday
0 Kudos
ReneRubalcava
Esri Frequent Contributor
Have you tried adding a console.log(); inside getStateCount to make sure it is firing?
0 Kudos
StevenGriffith
Deactivated User
I'd suggest adding an error return function to the QueryTask.execute call to do two things: 1) identify any errors on the server side and 2) to set your variable value to 0 so you don't get "undefined" value errors later in your code.

Steve G.
0 Kudos
Udaya_BhaskerCheerala
Emerging Contributor
I followd the suggested steps. But still Iam not able to get the value.

Thanks,
Uday
0 Kudos