<?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: How to access data in array after Promise in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-access-data-in-array-after-promise/m-p/1241427#M79650</link>
    <description>&lt;P&gt;Still hoping someone can chime in on how to get the variables in the issue.png file I show above.&amp;nbsp; The values in the Promise I'm not sure how to access.&amp;nbsp; &amp;nbsp;Thank you.&lt;/P&gt;</description>
    <pubDate>Thu, 15 Dec 2022 00:33:33 GMT</pubDate>
    <dc:creator>JohnRitsko1</dc:creator>
    <dc:date>2022-12-15T00:33:33Z</dc:date>
    <item>
      <title>How to access data in array after Promise</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-access-data-in-array-after-promise/m-p/1234142#M79414</link>
      <description>&lt;P&gt;I tried to revive this thread below but to no luck.&amp;nbsp; Rene has helped me quite a bit but I'm stuck getting values out of a promise statement that puts values into an array.&lt;/P&gt;&lt;P&gt;Previous Post:&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-api-for-javascript-questions/executing-a-series-of-queries-inside-a-loop/td-p/749954" target="_blank" rel="noopener"&gt;https://community.esri.com/t5/arcgis-api-for-javascript-questions/executing-a-series-of-queries-inside-a-loop/td-p/749954&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code hits the swiftly API to get a list of closed bus stops.&amp;nbsp; This list of stops does not include a lat / lon value so what I do is then query the closedStop Feature class using the bus stop ID from the API in order t join these two results together.&amp;nbsp; I then have an array "RESULTS" but can't get into the promise.&amp;nbsp; I can see the values (see attached image array.png).&amp;nbsp; Just not sure how to get those out of the array.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Input is greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;    BTNelement.addEventListener('click', function(evt){
      view.graphics.removeAll(); // Clears all graphics before placing new updated ones onto the view
        var settings = {
          "url": 'https://api.goswift.ly/',
          "method": "GET",
          "timeout": 0,
          "headers": {
            "Authorization": "",
            "Content-Type": "application/json"
          }
        };
        $.ajax(settings).done(function (response) {  
          console.log("Number of Closed Stops: " + response.adjustments.length);

          loadData(response);

          async function loadData(response) {
            var i = 0;
            
            const queryPromises = response.adjustments.map((data) =&amp;gt; {
              // parse data for query              
              const query = new Query();
              var queryValue = "Id = " + data.details.stopIds;                
              query.where =  queryValue;
              query.outFields = ["*"];
              query.returnGeometry = false;
              apiStopNumber = data.details.stopIds;
              routeAffected = data.details.routesAffected;
              notes = data.notes;
              reason = data.reason;
              i++;
              return [ClosedBusStops.queryFeatures(query), routeAffected, notes, reason, apiStopNumber];
            });          
            
            const resultsArray = await Promise.allSettled(queryPromises);            
            // you now have an array of arrays for results, you can flatten them
            const results = resultsArray.flat();            
            // now you can create the graphics from the results
            //console.log(results);       
            doStuff(results);


          };

          



        }); 
    });

    function doStuff(results){
            console.log(results);       
          };&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 16:08:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-access-data-in-array-after-promise/m-p/1234142#M79414</guid>
      <dc:creator>JohnRitsko1</dc:creator>
      <dc:date>2022-11-22T16:08:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to access data in array after Promise</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-access-data-in-array-after-promise/m-p/1238262#M79575</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Please see the Issue.png file.&amp;nbsp; Perhaps I'm going about this wrong.&amp;nbsp; My issue is accessing the lat/lon within the results I get back.&amp;nbsp; I can get say the Bus Stop number using results[0].value[1].&amp;nbsp; However, it's when I try to get values from within the ResultsPromise that I can't seem to figure out.&amp;nbsp; The Issue.png shows the lat/lon but I can't put together how to get that data, i.e.&amp;nbsp; results[0].[0].PromiseResults.features[0].attributes.Xcoord and subsequently&amp;nbsp;results[0].[0].PromiseResults.features[0].attributes.Ycoord.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Dec 2022 15:12:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-access-data-in-array-after-promise/m-p/1238262#M79575</guid>
      <dc:creator>JohnRitsko1</dc:creator>
      <dc:date>2022-12-06T15:12:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to access data in array after Promise</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-access-data-in-array-after-promise/m-p/1241427#M79650</link>
      <description>&lt;P&gt;Still hoping someone can chime in on how to get the variables in the issue.png file I show above.&amp;nbsp; The values in the Promise I'm not sure how to access.&amp;nbsp; &amp;nbsp;Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 00:33:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-access-data-in-array-after-promise/m-p/1241427#M79650</guid>
      <dc:creator>JohnRitsko1</dc:creator>
      <dc:date>2022-12-15T00:33:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to access data in array after Promise</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-access-data-in-array-after-promise/m-p/1241805#M79658</link>
      <description>&lt;P&gt;SOLUTION:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;$.ajax(settings).done(function (response) {          
        //console.log("Number of Closed Stops: " + response.adjustments.length);
        
        loadData(response);

        //---------------------------------------------------------------------------
        async function loadData(response) {   
          var xValue = 0;
          var yValue = 0;        

          const queryPromises = response.adjustments.map((response) =&amp;gt; {
            const apiStopNumber = response.details.stopIds;
            const routeAffected = response.details.routesAffected;
            const notes = response.notes;
            const reason = response.reason;
            var pictureSymbol = {
              type: "picture-marker",
              url:"img/closedStop.jpg",
              height: 20,
              width: 20  
            };                    
            let query = ClosedBusStops.createQuery();            
            query.where =  "Id = " + apiStopNumber;
            query.outFields = ["Xcoord, Ycoord"];
            query.returnGeometry = false;

            ClosedBusStops.queryFeatures(query)
              .then(function(queryResponse) {               
                if (queryResponse.features.length !== 0) {
                  xValue = queryResponse.features[0].attributes.Xcoord;
                  yValue = queryResponse.features[0].attributes.Ycoord;                  
                  const busStop = new Point({
                    type: "point",
                    longitude: xValue,
                    latitude: yValue,
                    wkid: 4326 
                  });
                  popupClosedBusStops = {
                    title: "Bus Stop: " + apiStopNumber,
                    content:"&amp;lt;b&amp;gt;Route(s) Impacted: &amp;lt;/b&amp;gt;" + routeAffected + "&amp;lt;br/&amp;gt;" + 
                      "&amp;lt;b&amp;gt;Notes: &amp;lt;/b&amp;gt;" + notes + "&amp;lt;br/&amp;gt;" + 
                      "&amp;lt;b&amp;gt;Reason: &amp;lt;/b&amp;gt;" + reason
                  };
                  const busStopGraphic = new Graphic ({
                              geometry: busStop,
                              symbol: pictureSymbol,
                              popupTemplate: popupClosedBusStops
                          });

                  view.graphics.add(busStopGraphic);
                }
                else{
                  //console.log("Inactive Stop")
                };
            });
          });
        }; // End of async function loadData 
      }); // End of Ajax Call
    });&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 15 Dec 2022 23:41:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-access-data-in-array-after-promise/m-p/1241805#M79658</guid>
      <dc:creator>JohnRitsko1</dc:creator>
      <dc:date>2022-12-15T23:41:51Z</dc:date>
    </item>
  </channel>
</rss>

