0

I am working on a web map using ArcGIS JavaScript API. The map should be able to query a layer and show the result. Since this is my first time using query task of the API, I got some issue. Below is the syntax of the query part. When I clicked the button in webpage, It always give the error:

init.js:182 Error(…)y
@ init.js:182(anonymous function)
@ init.js:181c
@ init.js:66d
@ init.js:66resolve.callback
@ init.js:67c
@ init.js:66d
@ init.js:66resolve.callback
@ init.js:67c
@ init.js:66d
@ init.js:66resolve.callback
@ init.js:67c
@ init.js:66d
@ init.js:66resolve.callback
@ init.js:67(anonymous function)
@ init.js:185k
@ init.js:189q
@ init.js:189resolve
@ init.js:191a
@ init.js:190k
@ init.js:190q
@ init.js:189resolve
@ init.js:191a
@ init.js:190k
@ init.js:190q
@ init.js:189resolve
@ init.js:191a
@ init.js:190k
@ init.js:190q
@ init.js:189resolve
@ init.js:191n
@ init.js:150f
@ init.js:154

As you can see, I put some console in the syntax and here is the result:

executequery started
where statement completed in executequery function
myquerytask completed in executequery function

It looks like the queryTask has already been excuted but the showResults, which is the callback function, doesn't. Could anybody help me with the entry level problem?

var whereExpression = "";
myQueryTask = new QueryTask("http://arcgis-cabhpgis-2026970499.us-west-1.elb.amazonaws.com/arcgis/rest/services/HCIC/160524_interactive_map_jzz_v02/MapServer/0");
myQuery = new Query();
myQuery.returnGeomery = true;
myQuery.outFields=["*"];
myQuery.where = whereExpression;
function executeQuery(){
    console.log("executequery started");
    whereExpression = "";
    for(i=0;i<serviceList.length;i++){
        if(i==0) {
            whereExpression += ("ServiceProvided LIKE '%" + serviceList[i] + "%'");
        }
        else{
            whereExpression += (" AND ServiceProvided LIKE '%" + serviceList[i] + "%'");
        }
    }
    console.log("where statement completed in executequery function");
    myQueryTask.execute(myQuery,showResults);
    console.log("myquerytask completed in executequery function");
}
function showResults (results) {
    console.log("showresults started");
    document.getElementById("info").innerHTML = results.features.length;
}
on(dom.byId("applyServiceSelection"),"click",executeQuery);

1 Answer 1

0

Looking at the code it seems like the value of myQuery.where is an empty string.

Just before the line

myQueryTask.execute(myQuery,showResults);

assign the value to whereExpression like below

myQuery.where = whereExpression;
1
  • Thank you! I should move the myQuery.where = whereExpression; line into the for loop. Commented Jun 3, 2016 at 23:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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