Using dojo/promise/all I'm attempting to populate an infoTemplate with results from a queryTask which runs later in the script.

Our app returns an XY value from a geocoded address search and queries that value to see if it falls within a series of polygonal features. If it does it should pass a string for each of the three queries.

The query runs and the console doesn't log an error. However, the infoTemplate is blank

:enter image description here

I've tried to loop through the array results prior to instantiating the infoTemplate but I don't know that that's necessary. Also, I've found that I'm unable to manually set the title of the InfoTemplate using a string.

Code for adding graphic/calling array:

          function addPlaceGraphic(item, symbol) {
              var place = {};
              var attributes, infoTemplate, pt, graphic;
              pt = item.feature.geometry;
              place.address = item.name;
              place.score = item.feature.attributes.score;

              var trashQuery = runPWQuery(pt, trashLayer, "trash");
              var yardQuery = runPWQuery(pt, yardWasteLayer, "yardwaste");
              var recycleQuery = runPWQuery(pt, recyclingLayer, "recycling");

              all([trashQuery, yardQuery, recycleQuery]).then(function (results) {

                  //receive query responses, update attributes and add graphics

                  attributes = { trashQuery: pt.trashLayer, recycleQuery: pt.recyclingLayer, yardQuery: pt.yardWasteLayer };

                  infoTemplate = new InfoTemplate();
                  infoTemplate.setTitle("Scheduling Information");
                  infoTemplate.setContent("Trash: ${trashQuery}<br/>Recycling: ${recycleQuery}<br/>Mixed Bulk: ${yardQuery}");
                  graphic = new Graphic(pt, symbol, attributes, infoTemplate);

                  //add to map

Code later in script for queryTask/returning promise:

function runPWQuery(in_geometry , in_fl , in_container_id) {
        var query = new esri.tasks.Query();
        query.returnGeometry = true;
        query.outFields = ["*"];
        query.geometry = in_geometry;

       var promise = in_fl.queryFeatures(query, function(myresponse, io) {
              var temp_val;
              var values = [];
              var tstr;
              for (var il = 0; il < myresponse.features.length; il++) {
                  if (myresponse.features[il].attributes["MONDAY"] == "Yes") {
                      temp_val = "Monday";
                  else if (myresponse.features[il].attributes["TUESDAY"] == "Yes") {
                      temp_val = "Tuesday";
                  else if (myresponse.features[il].attributes["WEDNESDAY"] == "Yes") {
                      temp_val = "Wednesday";
                  else if (myresponse.features[il].attributes["THURSDAY"] == "Yes") {
                      temp_val = "Thursday";
                  else if (myresponse.features[il].attributes["FRIDAY"] == "Yes") {
                      temp_val = "Friday";
                  else {
                      //temp_val = "Other";
                      temp_val = myresponse.features[il].attributes["DESCRIPT"];

              var statCount = myresponse.features.length;
              if (statCount >= 1) {                    
                  $("#" + in_container_id).html(temp_val);
              else {
                  $("#" + in_container_id).html("");

              return temp_val;

          }, function (error) {
              console.log(dojo.toJson(error, true));

          //return promise
          return promise;


    function renderPWQuery() {

  • Your all.then(results) should return a collection of features. Does it look like results contains the correct information from the three queries? – Mintx Oct 6 '15 at 21:23
  • Yes, all.then(results) does return the Object array for each of the Feature Service Layers called by the queryTasks. Since the collection of features contains all fields for each of the Feature Layers I'm thinking that it'll be necessary to iterate through to identify the results based on the queryTask. – Seth Lewis Oct 6 '15 at 22:05

There's more than one way to do it, but I would expect something like this to parse the returned results:

all([trashQuery, yardQuery, recycleQuery]).then(function (results) {

  //receive query responses, update attributes and add graphics

  trashResults = results[0];
  yardResults = results[1];
  recycleResults = results[2];

  attributes = {"trashQuery":trashResults.attributes.WhateverAttribute,

  infoTemplate = new InfoTemplate("Scheduling Information","Trash: ${trashQuery}<br/>
    Recycling: ${recycleQuery}<br/>Mixed Bulk: ${yardQuery}");
  graphic = new Graphic(pt, symbol, attributes, infoTemplate);

You will probably need to check if one of the results are empty before assigning all the attribute values to attributes to avoid any errors.

  • Many thanks for the help. With your code I was able to reach a solution. – Seth Lewis Oct 8 '15 at 20:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.