I tried to revive this thread below but to no luck. Rene has helped me quite a bit but I'm stuck getting values out of a promise statement that puts values into an array.
Previous Post: https://community.esri.com/t5/arcgis-api-for-javascript-questions/executing-a-series-of-queries-inside-a-loop/td-p/749954
My code hits the swiftly API to get a list of closed bus stops. 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. I then have an array "RESULTS" but can't get into the promise. I can see the values (see attached image array.png). Just not sure how to get those out of the array.
Input is greatly appreciated.
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) => {
// 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);
};