0

Where in the code do I add an error message if nothing is returned?

     function execute() {
     //
     var queryTask = new QueryTask("http://sepa-app-gis01/arcgis/rest/services/live/SEARCH/MapServer/2");
     var query = new Query();
     query.returnGeometry = true;
     query.outFields = [
       "POSTCODE"
     ];
     query.text = dom.byId("Postcode").value.toUpperCase();
     queryTask.execute(query, showResults);
 };

Should I add Error to the queryTask.execute first??

queryTask.execute(query, showResults, Error)
4

The Error function will returns a result if something is wrong with the query, like an improperly formatted where statement or a incorrect URL. A result of no records found isn't an error. In your showResults function, you can test to see if any results were returned, like this:

function showResults(results){
    if (results.features.length === 0) {
        console.log("No features found.");
    } else {
        'do something
    }
});

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.