I have a feature layer that is hosted on ArcServer. It has a field called document_num that is a string.

I have a table of which one of the columns is a link that lets the user "view on map". When this link is clicked it launches a function that is supposed to query the specific document by passing in the appropriate document_num..

The question is how should the where clause be formatted. I am having trouble getting the query to return any results. It is running though.

For example: If document_num = 100

function zoomToDoc(num){
    var query = new Query();
    var qString = "document_num" + num;
    query.where = qString;




The console.log() in the above script produces "document_num=100". This runs successfully but returns no feature.

Should the where clause be structured such that quotes are wrapping the parameters? i.e. "document_num = '100'" or "'document_num'='100'"? I have tried all of the above but still return zero feature. And yes the number being supplied to the function is a valid entry.

Any thoughts as to where I am going wrong here?


Yes, for strings, the value needs to be quoted, use single quotes, like document='100' - there's an example in the API Reference https://developers.arcgis.com/javascript/3/jsapi/query-amd.html#where (if you're using version 3.x).

One way to check is to use the rest services directory, e.g. https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3/query?where=SUB_REGION%3D%27Pacific%27&outFields=SUB_REGION&returnGeometry=false&f=html


Instead of using queryFeatures , you can create a queryTask with your feature layer . just create a query and pass it as input of QueryTask.

    var deferred = new Deferred();
    var queryTask = new QueryTask(featureLayerurl)
    var query = new Query();
     query.geometry = geometry;        
    query.where = "document='100'";
    query.returnGeometry = true;
    query.outFields = ["*"];

    return deferred = queryTask.execute(query).addErrback(function (response) {
        return null;
    }).addCallback(function (response) {
        return response;
    }).then(function (response) {
        return response;

if you want to get the complete result , you have to pass query outfields like this

 query.outFields = ["*"];

or if you want to get a few columns only , you can set appropriate field names in outfield array, like this

 query.outFields = ["object_id"];

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.