<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: QueryTask: Get Value out of executeForCount() in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/querytask-get-value-out-of-executeforcount/m-p/1010607#M71130</link>
    <description>&lt;P&gt;The answer is pretty simple you are logging the value of flag var before the aSync process is complete.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var flag = 0;
queryTask.executeForCount(query, lang.hitch(this, function(count) {
  if(count &amp;gt; 0) {
    flag = 1; // Suppose this one fires instead of flag = 0
  } else {
    flag = 0;
  }
}));
// this line is executed before the executeForCount method returns
console.log(flag); // Still returns 0, I want it to return 1&lt;/LI-CODE&gt;&lt;P&gt;What you would need is something like this:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var flag = 0;
queryTask.executeForCount(query, lang.hitch(this, function(count) {
  if(count &amp;gt; 0) {
    flag = 1; // Suppose this one fires instead of flag = 0
  } else {
    flag = 0;
  }
  console.log(flag);
}));&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 17 Dec 2020 14:56:26 GMT</pubDate>
    <dc:creator>RobertScheitlin__GISP</dc:creator>
    <dc:date>2020-12-17T14:56:26Z</dc:date>
    <item>
      <title>QueryTask: Get Value out of executeForCount()</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/querytask-get-value-out-of-executeforcount/m-p/1010419#M71126</link>
      <description>&lt;P&gt;How to get the value assigned inside queryTask.executeForCount() to use elsewhere outside of it? In the following example, I want&amp;nbsp;flag = &lt;SPAN class="hljs-number"&gt;1&lt;/SPAN&gt; when count &amp;gt; &lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;. But when I access&amp;nbsp;flag outside of queryTask.executeForCount(), the value is not changed.&lt;/P&gt;&lt;P&gt;Note: the code runs in Web AppBuilder Developer Edition.&lt;/P&gt;&lt;PRE&gt;...
&lt;SPAN class="hljs-keyword"&gt;var&lt;/SPAN&gt; flag = &lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;;
queryTask.executeForCount(query, lang.hitch(&lt;SPAN class="hljs-built_in"&gt;this&lt;/SPAN&gt;, &lt;SPAN class="hljs-function"&gt;&lt;SPAN class="hljs-keyword"&gt;function&lt;/SPAN&gt;(&lt;SPAN class="hljs-params"&gt;count&lt;/SPAN&gt;) &lt;/SPAN&gt;{
  &lt;SPAN class="hljs-keyword"&gt;if&lt;/SPAN&gt;(count &amp;gt; &lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;) {
    flag = &lt;SPAN class="hljs-number"&gt;1&lt;/SPAN&gt;; &lt;SPAN class="hljs-comment"&gt;// Suppose this one fires instead of flag = 0&lt;/SPAN&gt;
  } &lt;SPAN class="hljs-keyword"&gt;else&lt;/SPAN&gt; {
    flag = &lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;;
  }
}));
&lt;SPAN class="hljs-built_in"&gt;console&lt;/SPAN&gt;.log(flag); &lt;SPAN class="hljs-comment"&gt;// Still returns 0, I want it to return 1&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2020 23:03:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/querytask-get-value-out-of-executeforcount/m-p/1010419#M71126</guid>
      <dc:creator>XuanKuai</dc:creator>
      <dc:date>2020-12-16T23:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: QueryTask: Get Value out of executeForCount()</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/querytask-get-value-out-of-executeforcount/m-p/1010607#M71130</link>
      <description>&lt;P&gt;The answer is pretty simple you are logging the value of flag var before the aSync process is complete.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var flag = 0;
queryTask.executeForCount(query, lang.hitch(this, function(count) {
  if(count &amp;gt; 0) {
    flag = 1; // Suppose this one fires instead of flag = 0
  } else {
    flag = 0;
  }
}));
// this line is executed before the executeForCount method returns
console.log(flag); // Still returns 0, I want it to return 1&lt;/LI-CODE&gt;&lt;P&gt;What you would need is something like this:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var flag = 0;
queryTask.executeForCount(query, lang.hitch(this, function(count) {
  if(count &amp;gt; 0) {
    flag = 1; // Suppose this one fires instead of flag = 0
  } else {
    flag = 0;
  }
  console.log(flag);
}));&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Dec 2020 14:56:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/querytask-get-value-out-of-executeforcount/m-p/1010607#M71130</guid>
      <dc:creator>RobertScheitlin__GISP</dc:creator>
      <dc:date>2020-12-17T14:56:26Z</dc:date>
    </item>
    <item>
      <title>Re: QueryTask: Get Value out of executeForCount()</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/querytask-get-value-out-of-executeforcount/m-p/1010816#M71136</link>
      <description>&lt;P&gt;Thank you for your reply. Yes I noticed that. In fact I really need the flag value to use it outside of the function. Is there a way to have the following code execute after this is completed? Or more simply, since I am looking for the count, is there a way to get the count out of it for following use?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Dec 2020 23:07:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/querytask-get-value-out-of-executeforcount/m-p/1010816#M71136</guid>
      <dc:creator>XuanKuai</dc:creator>
      <dc:date>2020-12-17T23:07:37Z</dc:date>
    </item>
    <item>
      <title>Re: QueryTask: Get Value out of executeForCount()</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/querytask-get-value-out-of-executeforcount/m-p/1010902#M71141</link>
      <description>&lt;P&gt;Xuan,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;You will need to start using function based programming methods and not in line code, like you are now. The code that needs to access the flag var needs to be called from the executeForCount handler. So normally I would put any code that needs access to a async process result inside its own function that is only called inside the result of the async promise result function.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2020 13:29:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/querytask-get-value-out-of-executeforcount/m-p/1010902#M71141</guid>
      <dc:creator>RobertScheitlin__GISP</dc:creator>
      <dc:date>2020-12-18T13:29:24Z</dc:date>
    </item>
  </channel>
</rss>

