<?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: Can't &amp;quot;save&amp;quot; a feature from QueryTask. Argh! in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/can-t-amp-amp-quot-save-amp-amp-quot-a-feature/m-p/318198#M29356</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You're still not waiting for the response to be done before proceeding.&amp;nbsp; You could do what your trying to do by nesting the second step inside a callback function:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

function getProjectReport(theFid) { 
&amp;nbsp; var theDocument, theGraphic 
&amp;nbsp; 
&amp;nbsp; returnTipShape(theFid,function(returnedShape){
&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log(theGraphic.attributes.PROJECT);
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .
&amp;nbsp; });
&amp;nbsp; 
&amp;nbsp; 
}

function returnTipShape(param,callback) {
&amp;nbsp; var theParam = param.split(",");

&amp;nbsp; var query = new esri.tasks.Query();&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp; query.where = "FID=" + theParam[0];
&amp;nbsp; query.outFields = ["*"];
&amp;nbsp; query.returnGeometry = true;
&amp;nbsp; var theShape; 
&amp;nbsp; 
&amp;nbsp; //Specify the appropriate point/line map service depending on what was clicked
&amp;nbsp; switch (theParam[1]) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; case "point":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var queryTask = new esri.tasks.QueryTask("http://dmc-arcgis.snoco.co.snohomish.wa.us/SnocoGISdev/rest/services/transportation/tipProjectsPoint/MapServer/0");&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;
&amp;nbsp;&amp;nbsp;&amp;nbsp; case "polyline":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var queryTask = new esri.tasks.QueryTask("http://dmc-arcgis.snoco.co.snohomish.wa.us/SnocoGISdev/rest/services/transportation/tipProjectsLine/MapServer/0");&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;
&amp;nbsp; }

&amp;nbsp; dQuery = queryTask.execute(query); 

&amp;nbsp; var dList = new dojo.DeferredList([dQuery]);
&amp;nbsp; dList.then(function(results) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; var featureSet = results[0];
&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.forEach(featureSet.features, function(feature) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; theShape = feature;&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;&amp;nbsp; callback(theShape);
&amp;nbsp; });
&amp;nbsp; 
&amp;nbsp; //return theShape;
}
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, you don't really need a deferredList in this case since you're only doing one call.&amp;nbsp; Deferred lists are really only necessary when you need to wait for the response from multiples requests.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 15:07:50 GMT</pubDate>
    <dc:creator>BillDaigle</dc:creator>
    <dc:date>2021-12-11T15:07:50Z</dc:date>
    <item>
      <title>Can't &amp;amp;quot;save&amp;amp;quot; a feature from QueryTask. Argh!</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/can-t-amp-amp-quot-save-amp-amp-quot-a-feature/m-p/318189#M29347</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This is probably pretty easy but I can't seem to get what I'm doing wrong. I have a function, kicked off via a button click, that queries a particular layer, and then does some additional queries &amp;amp; data retrieval against three other layers. Basically, I have one location and I want to extract information from three other datasets that overlap its spatial extent.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Anyways, what I've tried to do is an initial query to my layer which has my spatial location (using an FID which I pass to the function). Once I query that layer, I was to "save" the feature to a variable so I can quickly use it in my subsequent queryTask calls. Here's my simple code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;function getProjectReport(theFid) {&amp;nbsp; var theParam = theFid.split(",");&amp;nbsp;&amp;nbsp; var query = new esri.tasks.Query();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; query.where = "FID=" + theParam[0];&amp;nbsp; query.outFields = ["*"];&amp;nbsp; query.returnGeometry = true;&amp;nbsp;&amp;nbsp;&amp;nbsp; var theGraphic;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Specify the appropriate point/line map service depending on what was clicked&amp;nbsp; switch (theParam[1]) { &amp;nbsp; case "point": &amp;nbsp;&amp;nbsp; var queryTask = new esri.tasks.QueryTask("URL #1");&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; break; &amp;nbsp; case "polyline": &amp;nbsp;&amp;nbsp; var queryTask = new esri.tasks.QueryTask("URL #2");&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; break;&amp;nbsp; }&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; queryTask.execute(query,function(featureSet) {&amp;nbsp;&amp;nbsp; &amp;nbsp; dojo.forEach(featureSet.features, function(feature) { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; theGraphic = feature; &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; });&amp;nbsp; });&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log(theGraphic.attributes.PROJECT); }&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now, the queryTask finds my record but when it gets to my "console.log" line, it errors out and tells me that my variable theGraphic is undefined. I've defined my variable at the beginning of my function so why doesn't my assignment persist after the end ofmy forEach loop? How do I fix this so I can re-use theGraphic later on in my function?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Steve&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Oct 2012 19:10:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/can-t-amp-amp-quot-save-amp-amp-quot-a-feature/m-p/318189#M29347</guid>
      <dc:creator>SteveCole</dc:creator>
      <dc:date>2012-10-03T19:10:42Z</dc:date>
    </item>
    <item>
      <title>Re: Can't "save" a feature from QueryTask. Argh!</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/can-t-amp-amp-quot-save-amp-amp-quot-a-feature/m-p/318190#M29348</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You're passing the graphic to the console before the execute task has finished running.&amp;nbsp; Place the console.log inside the callback for the execute function. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;queryTask.execute(query,function(featureSet) {&amp;nbsp; 
&amp;nbsp; dojo.forEach(featureSet.features, function(feature) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; theGraphic = feature;&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;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log(theGraphic.attributes.PROJECT);
 }); &lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Just FYI, based on the above code, theGraphic is only going to represent the last item in the featureSet.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:07:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/can-t-amp-amp-quot-save-amp-amp-quot-a-feature/m-p/318190#M29348</guid>
      <dc:creator>BillDaigle</dc:creator>
      <dc:date>2021-12-11T15:07:40Z</dc:date>
    </item>
    <item>
      <title>Re: Can't "save" a feature from QueryTask. Argh!</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/can-t-amp-amp-quot-save-amp-amp-quot-a-feature/m-p/318191#M29349</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Bill,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There is only one item return via the query so that part is fine. The reason I included the console.log code line &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;outside&lt;/SPAN&gt;&lt;SPAN&gt; of the loop was to reinforce the point that my variable is not persisting beyond the scope of the forEach loop. This is something I want it to do.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Oct 2012 19:57:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/can-t-amp-amp-quot-save-amp-amp-quot-a-feature/m-p/318191#M29349</guid>
      <dc:creator>SteveCole</dc:creator>
      <dc:date>2012-10-03T19:57:50Z</dc:date>
    </item>
    <item>
      <title>Re: Can't "save" a feature from QueryTask. Argh!</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/can-t-amp-amp-quot-save-amp-amp-quot-a-feature/m-p/318192#M29350</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Bill's right, put some console.logs in around the code and you'll see the order that things get executed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Don't forget the QueryTask.execute() is async and won't block on execution...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's your original code, complete with bug but with some log outputs:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
function getProjectReport(theFid) {
 var theParam = theFid.split(",");

 var query = new esri.tasks.Query();&amp;nbsp;&amp;nbsp;&amp;nbsp; 
 query.where = "FID=" + theParam[0];
 query.outFields = ["*"];
 query.returnGeometry = true;
 
 var theGraphic;
 
 //Specify the appropriate point/line map service depending on what was clicked
 switch (theParam[1]) {
&amp;nbsp; case "point":
&amp;nbsp;&amp;nbsp; var queryTask = new esri.tasks.QueryTask("URL #1");&amp;nbsp; 
&amp;nbsp;&amp;nbsp; break;
&amp;nbsp; case "polyline":
&amp;nbsp;&amp;nbsp; var queryTask = new esri.tasks.QueryTask("URL #2");&amp;nbsp; 
&amp;nbsp;&amp;nbsp; break;
 }

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log("Calling execute()");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; queryTask.execute(query,function(featureSet) {
&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; console.log("Task callback called");
&amp;nbsp; dojo.forEach(featureSet.features, function(feature,i) {
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log("Looping through features, current feature index =" + i + " about to set theGraphic variable");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; theGraphic = feature;
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log("Have set theGraphic variable for feature index = " + i);
&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; });
 }); 
 console.log("Trying to log theGraphic stuff, this will fail...");
 console.log(theGraphic.attributes.PROJECT);
}
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:07:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/can-t-amp-amp-quot-save-amp-amp-quot-a-feature/m-p/318192#M29350</guid>
      <dc:creator>__Rich_</dc:creator>
      <dc:date>2021-12-11T15:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: Can't "save" a feature from QueryTask. Argh!</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/can-t-amp-amp-quot-save-amp-amp-quot-a-feature/m-p/318193#M29351</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes- I understand what Bill (and you) are saying.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What I'm not doing a good job of saying is that I want/need to access theGraphic variable &lt;/SPAN&gt;&lt;STRONG style="font-style: italic;"&gt;AFTER&lt;/STRONG&gt;&lt;SPAN&gt; the conclusion of the queryTask.Execute routine. I need to re-use the geometry and some of it's attributes for subsequent queries on additional datasets.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;As my code currently exists, I can't- and I don't know what to change to get it to behave in the manner I need. I thought by declaring theGraphic as a variable at the beginning of the function it would persist and be accessible throughout the entire function but it's not (or I'm using it wrong).&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Oct 2012 20:41:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/can-t-amp-amp-quot-save-amp-amp-quot-a-feature/m-p/318193#M29351</guid>
      <dc:creator>SteveCole</dc:creator>
      <dc:date>2012-10-03T20:41:47Z</dc:date>
    </item>
    <item>
      <title>Re: Can't "save" a feature from QueryTask. Argh!</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/can-t-amp-amp-quot-save-amp-amp-quot-a-feature/m-p/318194#M29352</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The variable should be persisting, you are just accessing it before it gets set.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;When you execute a query, your code continues running and the callback isn't&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;called until the request is ready. This is good, because it doesn't lock your screen&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;when you make a request, but you have to recognize that until your callback is actually&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;called, none of the code within it has taken place. This is what is happening to your&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;variable assignment.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The callback of the query is the ideal place to do work that depends on a variable in the query,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;because you are guaranteed that the query has completed. Thus, nesting your queries in callback&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;functions will allow you to take advantage of asynchronous without running into timing problems.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Oct 2012 21:27:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/can-t-amp-amp-quot-save-amp-amp-quot-a-feature/m-p/318194#M29352</guid>
      <dc:creator>WyattPearsall</dc:creator>
      <dc:date>2012-10-03T21:27:43Z</dc:date>
    </item>
    <item>
      <title>Re: Can't "save" a feature from QueryTask. Argh!</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/can-t-amp-amp-quot-save-amp-amp-quot-a-feature/m-p/318195#M29353</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Steve,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Are you trying to query multiple layers at the same time? If so perhaps this sample will help:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples/query_deferred_list.html"&gt;http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples/query_deferred_list.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The sample shows how to work with a dojo deferred list to get notified when multiple query tasks have completed.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Oct 2012 22:57:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/can-t-amp-amp-quot-save-amp-amp-quot-a-feature/m-p/318195#M29353</guid>
      <dc:creator>KellyHutchins</dc:creator>
      <dc:date>2012-10-03T22:57:21Z</dc:date>
    </item>
    <item>
      <title>Re: Can't "save" a feature from QueryTask. Argh!</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/can-t-amp-amp-quot-save-amp-amp-quot-a-feature/m-p/318196#M29354</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Yes- I understand what Bill (and you) are saying.&lt;BR /&gt;&lt;BR /&gt;What I'm not doing a good job of saying is that I want/need to access theGraphic variable &lt;STRONG style="font-style: italic;"&gt;AFTER&lt;/STRONG&gt; the conclusion of the queryTask.Execute routine. I need to re-use the geometry and some of it's attributes for subsequent queries on additional datasets.&lt;BR /&gt; &lt;BR /&gt;As my code currently exists, I can't- and I don't know what to change to get it to behave in the manner I need. I thought by declaring theGraphic as a variable at the beginning of the function it would persist and be accessible throughout the entire function but it's not (or I'm using it wrong).&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt;...and we understand what you are saying.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can access theGraphic variable, no problem there, it's just then when you try it hasn't been populated yet.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;See:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
function getProjectReport(theFid) {
 var theParam = theFid.split(",");

 var query = new esri.tasks.Query();&amp;nbsp;&amp;nbsp;&amp;nbsp; 
 query.where = "FID=" + theParam[0];
 query.outFields = ["*"];
 query.returnGeometry = true;
 
 var theGraphic = {attributes:{PROJECT:"nothing set yet"}};
 
 //Specify the appropriate point/line map service depending on what was clicked
 switch (theParam[1]) {
&amp;nbsp; case "point":
&amp;nbsp;&amp;nbsp; var queryTask = new esri.tasks.QueryTask("URL #1");&amp;nbsp; 
&amp;nbsp;&amp;nbsp; break;
&amp;nbsp; case "polyline":
&amp;nbsp;&amp;nbsp; var queryTask = new esri.tasks.QueryTask("URL #2");&amp;nbsp; 
&amp;nbsp;&amp;nbsp; break;
 }

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log("Calling execute()");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; queryTask.execute(query,function(featureSet) {
&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; console.log("Task callback called");
&amp;nbsp; dojo.forEach(featureSet.features, function(feature,i) {
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log("Looping through features, current feature index =" + i + " about to set theGraphic variable");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; theGraphic = feature;
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log("Have set theGraphic variable for feature index = " + i);
&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; });
 }); 
 console.log("Trying to log theGraphic stuff, this will output the initial value as the callback (probably, i.e. race conditions) hasn't fired yet...");
 console.log(theGraphic.attributes.PROJECT);
}
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You must wait for the QueryTask callback to do it's thing before trying to use any values it sets.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Why can't you trigger whatever code needs to use the graphic from inside the callback?&amp;nbsp; You could even pass the graphic out to another function - a callback from your callback if you like &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:07:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/can-t-amp-amp-quot-save-amp-amp-quot-a-feature/m-p/318196#M29354</guid>
      <dc:creator>__Rich_</dc:creator>
      <dc:date>2021-12-11T15:07:45Z</dc:date>
    </item>
    <item>
      <title>Re: Can't "save" a feature from QueryTask. Argh!</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/can-t-amp-amp-quot-save-amp-amp-quot-a-feature/m-p/318197#M29355</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ok, my apologies. The light bulb went off with Wyatt's description as to what's happening. So my problem is waiting until the callback finishes and it sounds like the deferredList that Kelly was suggesting might be the way to do this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's my attempt to incorporate deferredList-&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;function getProjectReport(theFid) { 
 var theDocument, theGraphic 
 
 theGraphic = returnTipShape(theFid);
 
 console.log(theGraphic.attributes.PROJECT);
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .
}

function returnTipShape(param) {
 var theParam = param.split(",");

 var query = new esri.tasks.Query();&amp;nbsp;&amp;nbsp;&amp;nbsp; 
 query.where = "FID=" + theParam[0];
 query.outFields = ["*"];
 query.returnGeometry = true;
 var theShape; 
 
 //Specify the appropriate point/line map service depending on what was clicked
 switch (theParam[1]) {
&amp;nbsp; case "point":
&amp;nbsp;&amp;nbsp; var queryTask = new esri.tasks.QueryTask("http://dmc-arcgis.snoco.co.snohomish.wa.us/SnocoGISdev/rest/services/transportation/tipProjectsPoint/MapServer/0");&amp;nbsp; 
&amp;nbsp;&amp;nbsp; break;
&amp;nbsp; case "polyline":
&amp;nbsp;&amp;nbsp; var queryTask = new esri.tasks.QueryTask("http://dmc-arcgis.snoco.co.snohomish.wa.us/SnocoGISdev/rest/services/transportation/tipProjectsLine/MapServer/0");&amp;nbsp; 
&amp;nbsp;&amp;nbsp; break;
 }

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dQuery = queryTask.execute(query); 

 var dList = new dojo.DeferredList([dQuery]);
 dList.then(function(results) {
&amp;nbsp; var featureSet = results[0];
&amp;nbsp; dojo.forEach(featureSet.features, function(feature) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; theShape = feature;&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; });
 });
 
 return theShape;
}
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I thought that if I put the queryTask and deferredList calls into a function, that would isolate the process until it finishes. Of course, I get the same error so it looks like I've just moved the same issue around.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:07:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/can-t-amp-amp-quot-save-amp-amp-quot-a-feature/m-p/318197#M29355</guid>
      <dc:creator>SteveCole</dc:creator>
      <dc:date>2021-12-11T15:07:48Z</dc:date>
    </item>
    <item>
      <title>Re: Can't "save" a feature from QueryTask. Argh!</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/can-t-amp-amp-quot-save-amp-amp-quot-a-feature/m-p/318198#M29356</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You're still not waiting for the response to be done before proceeding.&amp;nbsp; You could do what your trying to do by nesting the second step inside a callback function:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

function getProjectReport(theFid) { 
&amp;nbsp; var theDocument, theGraphic 
&amp;nbsp; 
&amp;nbsp; returnTipShape(theFid,function(returnedShape){
&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log(theGraphic.attributes.PROJECT);
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .
&amp;nbsp; });
&amp;nbsp; 
&amp;nbsp; 
}

function returnTipShape(param,callback) {
&amp;nbsp; var theParam = param.split(",");

&amp;nbsp; var query = new esri.tasks.Query();&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp; query.where = "FID=" + theParam[0];
&amp;nbsp; query.outFields = ["*"];
&amp;nbsp; query.returnGeometry = true;
&amp;nbsp; var theShape; 
&amp;nbsp; 
&amp;nbsp; //Specify the appropriate point/line map service depending on what was clicked
&amp;nbsp; switch (theParam[1]) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; case "point":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var queryTask = new esri.tasks.QueryTask("http://dmc-arcgis.snoco.co.snohomish.wa.us/SnocoGISdev/rest/services/transportation/tipProjectsPoint/MapServer/0");&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;
&amp;nbsp;&amp;nbsp;&amp;nbsp; case "polyline":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var queryTask = new esri.tasks.QueryTask("http://dmc-arcgis.snoco.co.snohomish.wa.us/SnocoGISdev/rest/services/transportation/tipProjectsLine/MapServer/0");&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;
&amp;nbsp; }

&amp;nbsp; dQuery = queryTask.execute(query); 

&amp;nbsp; var dList = new dojo.DeferredList([dQuery]);
&amp;nbsp; dList.then(function(results) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; var featureSet = results[0];
&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.forEach(featureSet.features, function(feature) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; theShape = feature;&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;&amp;nbsp; callback(theShape);
&amp;nbsp; });
&amp;nbsp; 
&amp;nbsp; //return theShape;
}
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, you don't really need a deferredList in this case since you're only doing one call.&amp;nbsp; Deferred lists are really only necessary when you need to wait for the response from multiples requests.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:07:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/can-t-amp-amp-quot-save-amp-amp-quot-a-feature/m-p/318198#M29356</guid>
      <dc:creator>BillDaigle</dc:creator>
      <dc:date>2021-12-11T15:07:50Z</dc:date>
    </item>
    <item>
      <title>Re: Can't "save" a feature from QueryTask. Argh!</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/can-t-amp-amp-quot-save-amp-amp-quot-a-feature/m-p/318199#M29357</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Many thanks to everyone's input in this thread. Getting this to work has been one of the toughest challenges for me since I started working with the javascript API. I do have things finally working but I did have to rethink my entire process. As several people pointed out, the callback routines were critical so I re-wrote my code to be less linear and more "modular." I had resisted this because of another constraint (this whole process will update an HTML template opened via an onClick event) but I did find a way. So to recap my solution...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My button's onClick event starts everything by calling this function:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;function getProjectReport2(param) { 
 var theParam = param.split(",");
 var theShape;
 var query = new esri.tasks.Query();&amp;nbsp;&amp;nbsp;&amp;nbsp; 
 query.where = "FID=" + theParam[0];
 query.outFields = ["*"];
 query.returnGeometry = true;

 //Specify the appropriate point/line map service depending on what was clicked
 switch (theParam[1]) {
 case "point":
&amp;nbsp;&amp;nbsp; var queryTask = new esri.tasks.QueryTask("http://dmc-arcgis.snoco.co.snohomish.wa.us/SnocoGISdev/rest/services/transportation/tipProjectsPoint/MapServer/0");&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp; break;
 case "polyline":
&amp;nbsp;&amp;nbsp; var queryTask = new esri.tasks.QueryTask("URL to Map Servce");&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp; break;
 }

 //The new browser window must be opened in the function called by the 'onClick' event so
 //the new window is created here and its associated variable is created with a global scope.
 //Calculate the center of the screen for placement of the new window
 var center_left = (screen.width / 2) - (1000 / 2);
 var center_top = (screen.height / 2) - (600 / 2); 
 newWindow = window.open('','mywindow','width=1000,height=600,menubar=yes,scrollbars=yes,left=' + center_left + ',top=' + center_top); 

 var dQuery = queryTask.execute(query,createDeferredResults);&amp;nbsp; 
}&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...which then passes the feature onto a separate callback function. I decided to use a deferredList as Kelly had suggested:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;function createDeferredResults(featureSet) {
 var dTractRace, dTractIncome, dTractLep;

 dojo.forEach(featureSet.features, function(feature) {
&amp;nbsp;&amp;nbsp; theTipProject = feature;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
 });
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
 var query = new esri.tasks.Query();&amp;nbsp;&amp;nbsp;&amp;nbsp; 
 query.outFields = ["*"];
 query.returnGeometry = true;
 query.geometry = theTipProject.geometry;
 
 qTractRace = new esri.tasks.QueryTask("URL Service #1");
 qTractIncome = new esri.tasks.QueryTask("URL Service #2");
 qTractLep = new esri.tasks.QueryTask("URL Service #3");
 
 dTractRace = qTractRace.execute(query);
 dTractIncome = qTractIncome.execute(query);
 dTractLep = qTractLep.execute(query);
 
 defQuery = new dojo.DeferredList([dTractRace,dTractIncome,dTractLep]);
 defQuery.then(handleCensusResults);
}&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Finally, another callback function where I finally get down to the task of updating my HTML template:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;function handleCensusResults(results) {
 var raceResults, incomeResults, lepResults;

 raceResults = results[0][1].features;
 incomeResults = results[1][1].features;
 lepResults = results[2][1].features;
 .
&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; .
 processRaceResults(raceResults);
}&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Once again, thank you ALL for helping me!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Steve&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:07:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/can-t-amp-amp-quot-save-amp-amp-quot-a-feature/m-p/318199#M29357</guid>
      <dc:creator>SteveCole</dc:creator>
      <dc:date>2021-12-11T15:07:53Z</dc:date>
    </item>
  </channel>
</rss>

