Select to view content in your preferred language

How to return QueryTask results?

3202
4
Jump to solution
02-13-2017 10:55 AM
by Anonymous User
Not applicable

How to return QueryTask results?  I read the QueryTask returns a promise and this has to be resolved asynchronous way.  I looked at other similar posting and one of them said QueryTask uses Deferred, but I am new to Dojo and I couldn't quite understand how Deferred works.  I searched references online as much as I can, but unfortunately, I couldn't find one that displays examples similar to my case.  I would appreciate any of your help.

Thank you,

Makiko

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
Drew
by
Frequent Contributor

After looking a  little closer i can see you are really asking how to get your buildingAttributes variable out...

So it would be more like this..

 _test:function()
{
     queryTask.execute(query, addPointsToMap).then(lang.hitch(this, this._onQueryComplete));
   
},

_onQueryComplete:function(results)
{
     console.debug(results)
}

View solution in original post

0 Kudos
4 Replies
Drew
by
Frequent Contributor

Your code looks fine  (assuming your query is valid) and your results are in the ' results' object..

Do a console.debug on that and you can see the result.

 queryTask.execute(query, addPointsToMap).then(function(results){
 
 console.debug(results)
 
 }));

Drew

0 Kudos
Drew
by
Frequent Contributor

After looking a  little closer i can see you are really asking how to get your buildingAttributes variable out...

So it would be more like this..

 _test:function()
{
     queryTask.execute(query, addPointsToMap).then(lang.hitch(this, this._onQueryComplete));
   
},

_onQueryComplete:function(results)
{
     console.debug(results)
}
0 Kudos
by Anonymous User
Not applicable

Hi Andrew,

Thank you so much!!  I need to familiar with lang.hitch.  Your answer is very useful!!

Thanks!!

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Line 18 below is where you need to add you console statement.

_getFeatureLayerAttributes: function(){
  // Add Building Footprint layer
  var queryTask = new QueryTask({
    url: "https://services.arcgis.com/.../arcgis/services/...FeatureServer/0"
  });
  var buildingAttributes = [];
  var query = new Query();
  query.where = 'Building_Height > -1';
  query.outFields = ['OBJECTID', 'Building_Height', 'Z_Min', 'Z_Max'];
  
  queryTask.execute(query).then(function(results){
    for(var i = 0; 1 < results.features.length; i++){
      var feature = results.features[i].attributes;
      var attr = {OBJECTID: feature.OBJECTID, Building_Height: feature.Building_Height,
                  Z_Min: feature.Z_Min, Z_Max: feature.Z_Max};
      buildingAttributes.push(attr); // <--- How to return this???
    }
    console.log(buildingAttributes); // <--- Right here is where you need to add it
  });
  //console.log(buildingAttributes) ---> This is not printed
},‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos