Hello everybody, I'm trying to query some data from a service table I wrote: var query = new Query(); query.outFields = [ " * " ]; query.returnGeometry = true; var queryTask = new QueryTask("url"); queryTask.execute(query,showResults); but the showResult is never executed , what is the reason ?? please help me
Solved! Go to Solution.
Sundus,
It looks like you are just wanting to display data from the feature class table. Adding a where clause will work for this purpose. Here is an example based on a sample from the ESRI JavaScript API page. I have modified it to use your service.
ESRI Sample: Query data without a map | ArcGIS API for JavaScript
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <!--The viewport meta tag is used to improve the presentation and behavior of the samples on iOS devices--> <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"> <title>Query Musanda Project Details</title> <script src="http://js.arcgis.com/3.13/"></script> <script> require([ "dojo/dom", "dojo/on", "esri/tasks/query", "esri/tasks/QueryTask", "dojo/domReady!" ], function(dom, on, Query, QueryTask) { on(dom.byId("execute"), "click", execute); function execute() { queryTask = new QueryTask("URL to your Map Service"); //build query filter query = new Query(); query.where = "ESRI_OID > 0"; query.returnGeometry = false; query.outFields = ["*"]; query.spatialRelationship = Query.SPATIAL_REL_INTERSECTS; queryTask.execute(query, showResults); } function showResults(results) { var resultItems = []; var resultCount = results.features.length; for (var i = 0; i < resultCount; i++) { var featureAttributes = results.features.attributes; for (var attr in featureAttributes) { resultItems.push("<b>" + attr + ":</b> " + featureAttributes[attr] + "<br>"); } resultItems.push("<br>"); } dom.byId("info").innerHTML = resultItems.join(""); } }); </script> </head> <body> Projects: <input id="execute" type="button" value="Get Details"> <br /> <br /> <div id="info" style="padding:5px; margin:5px; background-color:#eee;"> </div> </body> </html>
I hope this helps!
Regards,
Tom
Hello everybody,
I'm trying to query some data from a service table
I wrote:
var query = new Query();
query.outFields = [ " * " ];
query.returnGeometry = true;
var queryTask = new QueryTask("url");
queryTask.execute(query,showResults);
but the showResult is never executed , what is the reason ??
please help me
Sundus,
A more complete code listing would be helpful to diagnose your problem. It may be a poorly formed query that is not returning any results. Do you have a where clause or are you querying by an ID or spatially?
Regards,
Tom
queryTask = new esri.tasks.QueryTask(gpURL); //build query filter query = new esri.tasks.Query(); query.returnGeometry = false; query.outFields = ["*"]; query.geometry = geometry.mapPoint; query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS; queryTask.execute(query, successFunction, errorFunction);
Use the error callback and see what the response objects say. Also, what are you querying? A where-clause, by geography, etc?
thank you for replying me
I have a map service which contains a layer with one table, I want to reach the table attributes and store its values in an array in order to display them in a list.
I need all the data without specification that is why I did'nt use Where clause
I wrote an error function but it is also not executed
function successFunction(featureSet) {
go.alert('sucess','jjj');
}
function errorFunction(){
go.alert('error','tt')
}
function displayProjectList(){
queryTask = new QueryTask("url");
//build query filter
query = new Query();
query.returnGeometry = false;
query.outFields = ["*"];
query.geometry = geometry.mapPoint;
query.spatialRelationship = Query.SPATIAL_REL_INTERSECTS;
queryTask.execute(query, successFunction, errorFunction);
Sundus,
It looks like you are just wanting to display data from the feature class table. Adding a where clause will work for this purpose. Here is an example based on a sample from the ESRI JavaScript API page. I have modified it to use your service.
ESRI Sample: Query data without a map | ArcGIS API for JavaScript
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <!--The viewport meta tag is used to improve the presentation and behavior of the samples on iOS devices--> <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"> <title>Query Musanda Project Details</title> <script src="http://js.arcgis.com/3.13/"></script> <script> require([ "dojo/dom", "dojo/on", "esri/tasks/query", "esri/tasks/QueryTask", "dojo/domReady!" ], function(dom, on, Query, QueryTask) { on(dom.byId("execute"), "click", execute); function execute() { queryTask = new QueryTask("URL to your Map Service"); //build query filter query = new Query(); query.where = "ESRI_OID > 0"; query.returnGeometry = false; query.outFields = ["*"]; query.spatialRelationship = Query.SPATIAL_REL_INTERSECTS; queryTask.execute(query, showResults); } function showResults(results) { var resultItems = []; var resultCount = results.features.length; for (var i = 0; i < resultCount; i++) { var featureAttributes = results.features.attributes; for (var attr in featureAttributes) { resultItems.push("<b>" + attr + ":</b> " + featureAttributes[attr] + "<br>"); } resultItems.push("<br>"); } dom.byId("info").innerHTML = resultItems.join(""); } }); </script> </head> <body> Projects: <input id="execute" type="button" value="Get Details"> <br /> <br /> <div id="info" style="padding:5px; margin:5px; background-color:#eee;"> </div> </body> </html>
I hope this helps!
Regards,
Tom
Hi Mr .Tom
thank you for your reply, I have sent you a message of your linkedin account. please send me your feedback
could you please send me your email
Many thanks
You still want to query something. Tom's example is good, another typical 'dummy' query to get all data is: WHERE 1=1
thank you every body, it works well, although I still did'nt know why it did'nt execute the query, is it because I did'nt write where clause ??!!
thank you very much
Sundus,
Yes, you must query something. You can query by IDs, by attributes or spatially. Your original post had all the parameters except what to query.
Regards,
Tom