QueryTask.execute is not a function - Print.js WAB 2.10

877
2
Jump to solution
03-29-2019 07:44 AM
KeithAnderson
New Contributor III

I am using the RSheitlin's printing solution for posting attributes into TextElements on a report....which works great.

Decided to get the attributes from QueryTask rather than the graphicsLayer.

Hangs on queryTask.execute is not a function. Can't get past it. Ideas are welcome.

Researched all of RSheitlin's post on this in the past.

//See if there is a parcel search layer added to the map
        var plyr;
        array.some(this.map.graphicsLayerIds, lang.hitch(this, function (layerId) {
          var lyr = this.map.getLayer(layerId);
          if(lyr.name === "Search Results: Parcels"){
            plyr = lyr;
            return true;
          }
        }));

        var gra = this.map.infoWindow.getSelectedFeature();
        var ppid = gra.attributes.PID;

        var queryTask = new esriQueryTask("https://Default_xxxxxx/MapServer/171");

        var query = new esriQuery();
        query.returnGeometry = false;
        query.outFields = ["*"];
        query.where = "PID = '" + ppid + "'";
        queryTask.execute(query, lang.hitch(this, function(results) {
          console.log(results.features)
        })); 


        if(plyr){‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Keith

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
Noah-Sager
Esri Regular Contributor

If "queryTask.execute is not a function" is the error, then I would check to make sure that you are creating the QueryTask correctly (ensure that you are correctly importing the module and that the local argument name matches up, e.g. require(["esri/tasks/QueryTask"], function(QueryTask). Then I would inspect the queryTask object in the console and make sure it looks right.

View solution in original post

2 Replies
Noah-Sager
Esri Regular Contributor

If "queryTask.execute is not a function" is the error, then I would check to make sure that you are creating the QueryTask correctly (ensure that you are correctly importing the module and that the local argument name matches up, e.g. require(["esri/tasks/QueryTask"], function(QueryTask). Then I would inspect the queryTask object in the console and make sure it looks right.

KeithAnderson
New Contributor III

Hi Noah

Thanks for the reply.

I finally found it just before I saw your message.

Uncaught Type error: queryTask is not a function


The order of dependencies in your require statement have to match the order of the corresponding variable names.

I assumed that ESRI Print.js in WAB would match, but they do not!

There are approximately 47 dependencies in the define but only 31 variable names in the function.

I added in the missing digit/form variables so everything lined up.

The two new variables I added at the bottom were fine all the time but because they did not correspond to the define dependencies they always failed with error.

I think its safe for me to say that Uncaught Type error: xxxxx is not a function is a probable issue with your variable names and variable counts at the top of your Define.

Thanks again!