Select to view content in your preferred language

esri.tasks.Query error "e is undefined"

1141
5
01-09-2014 06:57 AM
AleydisG__Pere
Regular Contributor
This is the function I use for the queries in my app:
function queryArcGIS(serviceId, layerId, where, outFields, blnGeomIn, geom, relGeom, blnGeomOut, callback, evt, bUserQuery){

 //Workaround Bug NIM-086349 migració 10.1
 var random = (new Date()).getTime();
 where += " AND " + random + "=" + random;

 AG_QueryTask = null;
 AG_QueryTask = new esri.tasks.QueryTask("http://mydomain/SIG/rest/services/"+serviceId+"/MapServer/"+layerId);

 //Query filter
 var query = new esri.tasks.Query();
 if (blnGeomIn) {
  query.geometry = geom;
  query.spatialRelationship=relGeom;
 }
 query.outSpatialReference = map.spatialReference; 
        query.returnGeometry = blnGeomOut;
        query.outFields = outFields;
 query.where=where;


 AG_QueryTask.execute(query, function(featureSet) {  
  callback(featureSet,evt); 
 }, function(error){
  hideLoading();
  if (bUserQuery && error.message == "timeout exceeded") {missatge("Error",_("Took too long to answer. Try again"));}
  else {errorMessage(error);}
 });


It used to work with version 2.1 of the API, but with v. 3.7 I get a "e is undefined" error and I can't find why.
I've been checking the esri.tasks.QueryTask and esri.tasks.Query documentation but I don't see what may be causing this error.

Firebug console gives me this info:

.cache["esri/tasks/query"]/</b<.toJson()               /3.7/ (line 484)
.cache["esri/tasks/QueryTask"]/</g<.execute()      /3.7/ (line 272)
.cache["esri/geometry/normalizeUtils"]/</B._createWrappers/</b[a.n]()   /3.7/ (line 607)
queryArcGIS()       myarcgis.js (line 1301)
init()                       myarcgis.js (line 134)
.cache["dojo/ready"]/</b.addOnLoad/e<()        /3.7/ (line 238)
.cache["dojo/ready"]/</h()                       /3.7/ (line 237)
.cache["dojo/ready"]/</b.addOnLoad()         /3.7/ (line 238)
initialize()                          myarcgis.js (line 51)
onload()                         index.html (line 1)
0 Kudos
5 Replies
JonathanUihlein
Esri Regular Contributor
Hi Aleydis!

Code seems fine at a quick glance (however, I cannot tell from this code if your external variables are correct...)
If its not too much trouble, could you recreate a sample showing the issue using http://jsfiddle.net/ ?

On a different note, glad to hear you've migrated to 3.7 from 2.1!
There have been been a lot of new and exciting features added since version 2.1; hopefully you find them useful 😃
0 Kudos
KenBuja
MVP Esteemed Contributor
Take a look at this thread, which refers to the documentation page about events. What you'll probably need is something like this

AG_QueryTask.execute(query, function(featureSet) {        
        callback(featureSet,evt);    
    }, function(returnedEvent){
        hideLoading();
        if (bUserQuery && returnedEvent.error.message == "timeout exceeded") {missatge("Error",_("Took too long to answer. Try again"));}
        else {errorMessage(returnedEvent.error);}
    });
0 Kudos
AleydisG__Pere
Regular Contributor
The origin of the error is here:
query.outSpatialReference = map.spatialReference; 


According to the documentation for the outSpatialReference property for esri.tasks.query:
If not specified, the geometry is returned in the spatial reference of the map.

So I comented the line and it works.
It also works if I change that line into this:
query.outSpatialReference = {"wkid":25831};


So with that other line the outSpatialReference property was not retrieving the wkid from my map's spatial reference and it remained undefined. Any idea?? Is it a bug?
0 Kudos
KenBuja
MVP Esteemed Contributor
It could be an issue where the map hasn't been initialized by the time you try to get its spatialReference property. Have you tried putting this in the map's onLoad or onLayersAddResult event?
0 Kudos
AleydisG__Pere
Regular Contributor
I'm already using the map's onLoad event. But it's not working as it should. I think it has to do with using a proxy page. Weird.
I'll look further into it tomorrow at work.
0 Kudos