Return value from queryTask.execute()

Discussion created by udbk on Feb 7, 2013
Latest reply on Feb 8, 2013 by udbk
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()
// I will write my logic here but in this function Iam getting featCount = 'undefined'
// I will write my logic here