Thank You Kelly,
This has to be the correct approach, but after incorporating your suggestion the map is setting and printing only the last tile extent in the collection. But at least it is no longer producing multiple prints of the last extent.
The for loop does not wait for the asynchronous setExtent to complete before moving onto the next extent.
I've read through the recommended "Keeping Promises" and a few other articles/threads ("Correct way to write loops for promise", "Dojo Deferreds and Promises") but I'm still not crystal clear how to achieve a loop effectively with asynchronous calls. Looks like you can't really use a traditional loop and instead will have to look at restructuring this to chain things together.
Here is the updated function, that sets and prints only the last extent in the collection. Looking at the "Chain it up" example in the "Keeping Promises" article seems like the GridIndexPoint function below should work. But line 8 runs through all of the GridIndexfeatures.length before lines 12 & 13 are written to the console.
GridIndexPrint = function () {
dom.byId("mapBusyIndicatorMessage").innerHTML = "Processing...";
showMapBusyIndicator();
console.log("length", GridIndexfeatures.length);
for (var f = 0, fl = GridIndexfeatures.length; f < fl; f++) {
console.log("f", f);
var feature = GridIndexfeatures;
var tmpExtent = new Extent(feature.geometry.getExtent().xmin, feature.geometry.getExtent().ymin, feature.geometry.getExtent().xmax, feature.geometry.getExtent().ymax, new SpatialReference({ wkid: 102100 }));
theMap.setExtent(tmpExtent).then(function () {
console.log(f, "Extent has been set - ready to print", tmpExtent);
console.log("PageNumber: " + feature.attributes.PageNumber, "PageName: " + feature.attributes.PageName);
Print("PNG8.5x11Land");
});
}
hideMapBusyIndicator();
}