<?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: Executing a series of queries inside a loop in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/executing-a-series-of-queries-inside-a-loop/m-p/749957#M69379</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much! This helps a lot. I have a couple of follow up questions. First, Aptana gives me an error for the use of comma in this line&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;all(queries).then(, function(results){&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I removed the comma, and it seems to be working fine. Is that OK?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Second issue is another one that confuses me. As I mentioned before, I use this loop to build a bookmarks list (following this example &lt;A href="https://developers.arcgis.com/javascript/3/jssamples/widget_bookmarks_dropdownbutton.html" title="https://developers.arcgis.com/javascript/3/jssamples/widget_bookmarks_dropdownbutton.html"&gt;Bookmarks widget | ArcGIS API for JavaScript&lt;/A&gt;), which I defined as&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;bookmarks = new esri.dijit.Bookmarks({&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; map: map,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;}, dojo.byId('bookmarks')); &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;I then created a temp bookmark:&lt;/SPAN&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;var tempBookmark ={&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "extent": {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "spatialReference": {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "wkid": 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; },&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "xmin":0,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "ymin":0,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "xmax":0,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "ymax":0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; },&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "name": "Temp"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;In the procedure you described, I assigned the extents of the results&lt;J&gt; to the tempBookmark. I also assigned the tempBookmark name using allSysNames&lt;J&gt;. Here is the more complete piece of the code:&lt;/J&gt;&lt;/J&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;all(queries).then(function(results){&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // another for loop&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (var j = 0; j &amp;lt; results.length; j++) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log("j inside query task equals to: " + j);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log(results&lt;J&gt;.extent);&lt;/J&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tempBookmark.extent = results&lt;J&gt;.extent;&lt;/J&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tempBookmark.name = allSysNames&lt;J&gt;;&lt;/J&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log(tempBookmark.extent);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bookmarks.addBookmark(tempBookmark);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;});&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;So the bookmark list is built just fine, with the correct names from the allSysNames array. Apparently the statement &lt;SPAN style="font-family: 'courier new', courier;"&gt;tempBookmark.name = allSysNames&lt;J&gt;;&lt;/J&gt;&lt;/SPAN&gt; works as expected. However the problem is with the actual extents. I have 5 items in the bookmarks list, and no matter which one I click, it zooms to the extents of the last item in the array. For debugging purposes I logged the values of the elements (xmin, xmax, ymin, ymax) of tempBookmark.extent, and they are same as corresponding results&lt;J&gt;.extent values. But those values apparently do not properly get transferred to the bookmarks. It is strange because the bookmark name appears to be updated just fine.&lt;/J&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 05 May 2016 22:15:02 GMT</pubDate>
    <dc:creator>NaciDilekli</dc:creator>
    <dc:date>2016-05-05T22:15:02Z</dc:date>
    <item>
      <title>Executing a series of queries inside a loop</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/executing-a-series-of-queries-inside-a-loop/m-p/749954#M69376</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to loop through a string array of place names, build a query statement for each place, get the extent for the place, and build a bookmarks list. I am however baffled with how the results are built. Basically, it looks like while the query task is located inside the loop, it waits for the loop to finish to be executed. Therefore I get multiple and identical query results in the end. The core of the problem can be shown with this piece of code:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;for (i = 1; i &amp;lt; allSysNames&lt;I&gt;.length; i++) {&lt;/I&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; query.where = "SysName =" + allSysNames&lt;I&gt;;&lt;/I&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log("i inside the loop is: " + i);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; queryTask.executeForExtent(query, function(result){&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log("i inside query task equals to: " + i);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;console.log("outside the loop");&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The log is the following. &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;i inside the loop is: 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;i inside the loop is: 2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;i inside the loop is: 3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;outside the loop&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;i inside query task equals to 4&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;i inside query task equals to 4&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;i inside query task equals to 4&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am probably missing something very basic here, as I am new to Javascript and the API. What do I need to execute the queryTask for my purposes? Thank you!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Naci&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 May 2016 19:06:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/executing-a-series-of-queries-inside-a-loop/m-p/749954#M69376</guid>
      <dc:creator>NaciDilekli</dc:creator>
      <dc:date>2016-05-05T19:06:03Z</dc:date>
    </item>
    <item>
      <title>Re: Executing a series of queries inside a loop</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/executing-a-series-of-queries-inside-a-loop/m-p/749955#M69377</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Those query tasks are asynchronous, so won't be executed immediately.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You have a couple of options&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;var queries = [];
for (i = 1; i &amp;lt; allSysNames&lt;I&gt;.length; i++) {&lt;/I&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; query.where = "SysName =" + allSysNames&lt;I&gt;;&lt;/I&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log("i inside the loop is: " + i);
&amp;nbsp;&amp;nbsp;&amp;nbsp; queries.push(queryTask.executeForExtent(query));
}
// dojo/promise/all
all(queries).then(, function(results){
&amp;nbsp;&amp;nbsp;&amp;nbsp; // another for loop
&amp;nbsp;&amp;nbsp;&amp;nbsp; for (var j = 0; j &amp;lt; results.length; j++) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log("j inside query task equals to: " + j);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
});
console.log("outside the loop");


// or


// I prefer this method
var queries = allSysNames.map(function(name) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; query.where = "SysName =" + name;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return queryTask.executeForExtent(query)
});
// dojo/promise/all
all(queries).then(, function(results){
&amp;nbsp;&amp;nbsp;&amp;nbsp; // another for loop
&amp;nbsp;&amp;nbsp;&amp;nbsp; for (var j = 0; j &amp;lt; results.length; j++) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log("j inside query task equals to: " + j);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
});
console.log("outside the loop");&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a couple of posts on Promises you could check out.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migration-blogpost/54740" target="_blank"&gt;Keeping Promises&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://odoe.net/blog/arcgis-javascript-promises/" title="http://odoe.net/blog/arcgis-javascript-promises/" rel="nofollow noopener noreferrer" target="_blank"&gt;ArcGIS JavaScript Promises - odoenet&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since the Promises is asynchronous, it will finish after your last console statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope that helps a bit.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 07:51:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/executing-a-series-of-queries-inside-a-loop/m-p/749955#M69377</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2021-12-12T07:51:45Z</dc:date>
    </item>
    <item>
      <title>Re: Executing a series of queries inside a loop</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/executing-a-series-of-queries-inside-a-loop/m-p/749956#M69378</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;One more useful thing to know about Promises is that they are returned in the same order that they are passed in. Therefore, you'll always know that result1 will be what's returned from query1, result2 will be what's returned from query2, etc&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 May 2016 20:39:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/executing-a-series-of-queries-inside-a-loop/m-p/749956#M69378</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2016-05-05T20:39:06Z</dc:date>
    </item>
    <item>
      <title>Re: Executing a series of queries inside a loop</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/executing-a-series-of-queries-inside-a-loop/m-p/749957#M69379</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much! This helps a lot. I have a couple of follow up questions. First, Aptana gives me an error for the use of comma in this line&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;all(queries).then(, function(results){&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I removed the comma, and it seems to be working fine. Is that OK?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Second issue is another one that confuses me. As I mentioned before, I use this loop to build a bookmarks list (following this example &lt;A href="https://developers.arcgis.com/javascript/3/jssamples/widget_bookmarks_dropdownbutton.html" title="https://developers.arcgis.com/javascript/3/jssamples/widget_bookmarks_dropdownbutton.html"&gt;Bookmarks widget | ArcGIS API for JavaScript&lt;/A&gt;), which I defined as&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;bookmarks = new esri.dijit.Bookmarks({&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; map: map,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;}, dojo.byId('bookmarks')); &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;I then created a temp bookmark:&lt;/SPAN&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;var tempBookmark ={&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "extent": {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "spatialReference": {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "wkid": 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; },&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "xmin":0,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "ymin":0,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "xmax":0,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "ymax":0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; },&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "name": "Temp"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;In the procedure you described, I assigned the extents of the results&lt;J&gt; to the tempBookmark. I also assigned the tempBookmark name using allSysNames&lt;J&gt;. Here is the more complete piece of the code:&lt;/J&gt;&lt;/J&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;all(queries).then(function(results){&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // another for loop&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (var j = 0; j &amp;lt; results.length; j++) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log("j inside query task equals to: " + j);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log(results&lt;J&gt;.extent);&lt;/J&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tempBookmark.extent = results&lt;J&gt;.extent;&lt;/J&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tempBookmark.name = allSysNames&lt;J&gt;;&lt;/J&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log(tempBookmark.extent);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bookmarks.addBookmark(tempBookmark);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;});&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;So the bookmark list is built just fine, with the correct names from the allSysNames array. Apparently the statement &lt;SPAN style="font-family: 'courier new', courier;"&gt;tempBookmark.name = allSysNames&lt;J&gt;;&lt;/J&gt;&lt;/SPAN&gt; works as expected. However the problem is with the actual extents. I have 5 items in the bookmarks list, and no matter which one I click, it zooms to the extents of the last item in the array. For debugging purposes I logged the values of the elements (xmin, xmax, ymin, ymax) of tempBookmark.extent, and they are same as corresponding results&lt;J&gt;.extent values. But those values apparently do not properly get transferred to the bookmarks. It is strange because the bookmark name appears to be updated just fine.&lt;/J&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 May 2016 22:15:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/executing-a-series-of-queries-inside-a-loop/m-p/749957#M69379</guid>
      <dc:creator>NaciDilekli</dc:creator>
      <dc:date>2016-05-05T22:15:02Z</dc:date>
    </item>
    <item>
      <title>Re: Executing a series of queries inside a loop</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/executing-a-series-of-queries-inside-a-loop/m-p/749958#M69380</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For the first one, that was a typo on my part, sorry.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For second one&lt;/P&gt;&lt;P&gt;The tempBookmark you are updating is a single bookmark, so you keep updating the same one and adding it multiple times, but inside the bookmark widget, you basically added the same bookmark multiple times.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Create a new bookmark on each loop and you should be ok.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 May 2016 14:03:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/executing-a-series-of-queries-inside-a-loop/m-p/749958#M69380</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2016-05-06T14:03:55Z</dc:date>
    </item>
    <item>
      <title>Re: Executing a series of queries inside a loop</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/executing-a-series-of-queries-inside-a-loop/m-p/749959#M69381</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks a lot, that solved my problem!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 May 2016 15:29:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/executing-a-series-of-queries-inside-a-loop/m-p/749959#M69381</guid>
      <dc:creator>NaciDilekli</dc:creator>
      <dc:date>2016-05-06T15:29:51Z</dc:date>
    </item>
    <item>
      <title>Re: Executing a series of queries inside a loop</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/executing-a-series-of-queries-inside-a-loop/m-p/749960#M69382</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rene,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why doesn't this work? Where &lt;EM&gt;visible&lt;/EM&gt; is coming from an array of layerId's that are providing indexes for myQuery (it works for any random array eg ["alpha", "beta", "charlie"]:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;var myQuery = ["Population&amp;gt;10000" , "Hispanic &amp;gt; 1500" , "Employees &amp;gt; 10000"];&lt;BR /&gt; &lt;BR /&gt; var result = visible.map(function(e) {&lt;BR /&gt; return myQuery&lt;E&gt;;&lt;BR /&gt; });&lt;/E&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Apr 2017 00:43:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/executing-a-series-of-queries-inside-a-loop/m-p/749960#M69382</guid>
      <dc:creator>JamesOsundwa</dc:creator>
      <dc:date>2017-04-27T00:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: Executing a series of queries inside a loop</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/executing-a-series-of-queries-inside-a-loop/m-p/1229685#M79269</link>
      <description>&lt;P&gt;Rene, I hope you have chance to see this as I have a similar question as this.&amp;nbsp; I understand that I can't call a query inside of a for loop.&amp;nbsp; Here is what I am trying to do.&amp;nbsp; I reach out to an API that returns information on Bus Stops that are currently closed.&amp;nbsp; I want to display these Bus Stops on a map but the information from the API doesn't include lat/lon.&amp;nbsp; So what I do is take the response from the API and iterate through them getting the Bus Stop number and then running a query on our Bus Stop Feature Class that can return the lat/lon that I in turn create a graphics layer from.&amp;nbsp; Problem of course is the query doesn't work as expected.&amp;nbsp; Wondering how I can incorporate your answer above into my scenario.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;layerList.on("trigger-action", (event) =&amp;gt; {&lt;BR /&gt;const id = event.action.id;&lt;BR /&gt;if (id === "refresh-ClosedBusStops") {&lt;BR /&gt;var settings = {&lt;BR /&gt;"url": 'api to get closed bus stops',&lt;BR /&gt;"method": "GET",&lt;BR /&gt;"timeout": 0,&lt;BR /&gt;"headers": {&lt;BR /&gt;"Authorization": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",&lt;BR /&gt;"Content-Type": "application/json"&lt;BR /&gt;}&lt;BR /&gt;};&lt;BR /&gt;$.ajax(settings).done(function (response) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; var Xcoord = 0;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; var Ycoord = 0;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; for(i = 0; i &amp;lt; response.adjustments.length; i+=1) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; busID = response.adjustments[i].details.stopIds;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; routeAffected = response.adjustments[i].details.routesAffected;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; notes = response.adjustments[i].notes;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; reason = response.adjustments[i].reason;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; const query = new Query();&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; var queryValue = "Id = " + response.adjustments[i].details.stopIds;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; query.where = queryValue;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; query.outFields = [ "Xcoord", "Ycoord" ];&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; query.returnGeometry = true;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; ClosedBusStops.queryFeatures(query).then(function(results) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Xcoord = results.features[0].attributes.Xcoord;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Ycoord = results.features[0].attributes.Ycoord;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; createClosedBusStop(busID, routeAffected, notes, reason, Xcoord, Ycoord);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; });&lt;BR /&gt;&amp;nbsp; &amp;nbsp; };&lt;BR /&gt;});&lt;BR /&gt;}&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;function createClosedBusStop(busID, routeAffected, notes, reason, Xcoord, Ycoord) {&lt;BR /&gt;const busStop = new Point({&lt;BR /&gt;&amp;nbsp; type: "point",&lt;BR /&gt;&amp;nbsp; longitude: Xcoord,&lt;BR /&gt;&amp;nbsp; latitude: Ycoord,&lt;BR /&gt;&amp;nbsp; wkid: 4326&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;var markerSymbol = {&lt;BR /&gt;&amp;nbsp; type: "simple-marker",&lt;BR /&gt;&amp;nbsp; style: "square",&lt;BR /&gt;&amp;nbsp; color: "RED",&lt;BR /&gt;&amp;nbsp; size: "10px"&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;popupClosedBusStops = {&lt;BR /&gt;&amp;nbsp; title: "Bus Stop: " + busID,&lt;BR /&gt;&amp;nbsp; content:"&amp;lt;b&amp;gt;Route(s) Impacted: &amp;lt;/b&amp;gt;" + routeAffected + "&amp;lt;br/&amp;gt;" +&lt;BR /&gt;&amp;nbsp; "&amp;lt;b&amp;gt;Notes: &amp;lt;/b&amp;gt;" + notes + "&amp;lt;br/&amp;gt;" +&lt;BR /&gt;&amp;nbsp; "&amp;lt;b&amp;gt;Reason: &amp;lt;/b&amp;gt;" + reason&lt;BR /&gt;};&lt;BR /&gt;const busStopGraphic = new Graphic ({&lt;BR /&gt;&amp;nbsp; geometry: busStop,&lt;BR /&gt;&amp;nbsp; symbol: markerSymbol,&lt;BR /&gt;&amp;nbsp; popupTemplate: popupClosedBusStops&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;view.graphics.add(busStopGraphic);&lt;BR /&gt;};&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2022 21:36:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/executing-a-series-of-queries-inside-a-loop/m-p/1229685#M79269</guid>
      <dc:creator>JohnRitsko1</dc:creator>
      <dc:date>2022-11-08T21:36:51Z</dc:date>
    </item>
  </channel>
</rss>

