Select to view content in your preferred language

Query task not showing results

3384
11
Jump to solution
10-27-2015 04:00 AM
SadanandacharB1
Occasional Contributor

Hi All

I am doing query task using dojo and arcgis javscript,

but the result is not showing, there is no error, please help me, I am new to javascriptQueryTask.jpg

0 Kudos
1 Solution

Accepted Solutions
thejuskambi
Frequent Contributor

Hello Sadananachar,

I think that is because of the scope of function. first you need to use this._map and not just _map. Second you need to ensure that the scope of the fuction is at module level. this can be achieved by using lang.hitch. For query task it should be something like this.

queryTask.execute(query, lang.hitch(this, this.showResults));

Also in your case you need to ensure that the function where you are setting up the query (_onSubmitClick)is also in the same scope. But In your case it seems to be ok as you are already using this.showResults. If it is not working then you need to hitch it to the right scope as well.

Thejus

View solution in original post

11 Replies
TimWitt2
MVP Alum

Hi Sadanandachar,

When you run the query in chrome, open your developer console, go to the Network tab, run the query in your map and then right-click the query in the network tab and choose "open link in new tab".

Now where it says "query?f=json" in your link, replace json with html

Now you can see if your query is working properly.

Hope this helps!

Tim

0 Kudos
SadanandacharB1
Occasional Contributor

Hello Tim

Actually my main map is in another page, that is i am adding map in map.manager.js

and i am doing query task in another js module using dojo.

I debugged the code, here i am getting  error like "unable to get 'map' and  'graphics' property which is undefined or null".

How to solve this issue, Please help me

0 Kudos
thejuskambi
Frequent Contributor

You need either keep the map variable as apart of Global, or when you initialize your module which contains the query, pass the map object as constructor parameter.

0 Kudos
SadanandacharB1
Occasional Contributor

Can you please show me one sample example

Thank You

0 Kudos
thejuskambi
Frequent Contributor

When you create a module write something like this. I am just providing you a skeleton/overview.

define([...], {
    return declare([....], {
              _map: null,
              constructor: function(map){
                    this._map = map;
              },
              //other function/methods
          )};
});

and when you create the instance you create it like below, where map variable is esri map object

var myMod = new MyModule(map);   
SadanandacharB1
Occasional Contributor

Hi thejus

Actually i added a map instance like below but i am getting same errorQueryTaskError.jpg

0 Kudos
thejuskambi
Frequent Contributor

Hello Sadanandachar,

The code seems to be ok. Are you getting any error? or the queryResults has Features?

Check the developer Tools and network activitiy and see if there were any issues.

Try the same query on the rest api, and make sure the where clause is formed correctly.

Hope this was helpful.

Thejus

0 Kudos
TracySchloss
Honored Contributor

Why all the changing the extents so many times?  Before you go to the trouble of stepping through each resultFeature, I'd comment both the if loop and the for loop and make sure you're getting results returned at all.  It could be you have results, but you have an issue with setting your extents.  It's always possible you aren't on the right place in your map. 

I'd also recommend checking your where clause at the rest endpoint and make sure you're getting data from there.  Are you familiar with how to do this?   If you navigate to the URL you have in the queryTask, scroll down to the bottom where it shows Supported Operations and choose Query.

At the top of that form, there is a place you can paste your where clause.  Use actual values, not your variables, because this is a self contained kind of test.   Be sure and set the outFields to *.  Then run this, choosing either select GET or POST, I have found that it matters for this kind of test.  If it doesn't return results successfully here, it won't work in your code either. 

0 Kudos
SadanandacharB1
Occasional Contributor

Hi thejus

Actually i added a map instance like below but i am getting same errorQueryTaskError.jpg

0 Kudos