AnsweredAssumed Answered

"No records found" alert when using FindTask searching a service

Question asked by RWHupp on Jan 10, 2014
Latest reply on Jan 14, 2014 by RWHupp
I've been trying to find a way to fire an alert when a search is performed through a FindTask and no results are returned. I know it's probably and easy task but I can't figure it out. Can someone please help offer a solution?

Here's my function (from a template and help from the forums).

     function doFind() {         var findTask = new esri.tasks.FindTask("http://mapservices2.bexar.org/arcgis/rest/services/GecoVector/AFW_Test/MapServer");         findParams = new esri.tasks.FindParameters();         findParams.returnGeometry = true;         findParams.layerIds = [0];         findParams.searchFields = [ "WARRANT_NU", "LAST_NAME", "FIRST_NAME", "FULL_ADDRE", "ZIPCODE", "CASE_NUMBE", "OFFENSE_CO", "ISSUE_CODE", "CHARGE_DES"  ];         findParams.outSpatialReference = map.spatialReference;         findParams.searchText = dojo.byId("ownerName").value;         findTask.execute(findParams,showResults);       };        function showResults(results) {         map.graphics.clear();         var symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 25, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 1), new dojo.Color([0, 255, 0, 0.25]));         var items = dojo.map(results,function(result){           var graphic = result.feature;           graphic.setSymbol(symbol);           map.graphics.add(graphic);           return result.feature.attributes;         });


and the referencing html:

[HTML]<div data-dojo-props="region:'center'" data-dojo-type="dijit.layout.ContentPane" style="width:100%;height:100%;border:1px solid #000; margin:0; padding:0; overflow:hidden;">
        <div id="search" align="center"><b>Search Warrants:</b> <input type="text" id="ownerName" size="20" title="Search warrant number, name, address, case number, etc. Results will be highlighted on map and in table below map. Click on table row to zoom to record" />
          <button type="submit" data-dojo-type="dijit.form.Button"  data-dojo-props='onClick:function(){ doFind();}, value:"Search"'>Search</button>
    <button data-dojo-type="dijit.form.Button"  data-dojo-props='onClick:function(){ doClear();}, value:"Clear"'>Clear</button>
        </div>[/HTML]

In addition I would also like to have an alert for the zooming to point function here on the datagrid when clicking on results in table row returns no geometry.

 function onRowClickHandler(evt){         var clickedTaxLotId = grid.getItem(evt.rowIndex).OBJECTID;         var selectedTaxLot;         var distance = 100;          dojo.forEach(map.graphics.graphics,function(graphic){           if((graphic.attributes) && graphic.attributes.OBJECTID === clickedTaxLotId){             selectedTaxLot = graphic.geometry;             return;     }              });            var newExtent = new esri.geometry.Extent({           "xmin": selectedTaxLot.x - distance,           "ymin": selectedTaxLot.y - distance,           "xmax": selectedTaxLot.x + distance,           "ymax": selectedTaxLot.y + distance,           "spatialReference": {             "wkid": 102100           }         });         map.setExtent(newExtent);          };

[HTML]    <div data-dojo-type="dojox.layout.ExpandoPane"splitter="true" data-dojo-props="region:'bottom', title:'Search Results'" style="height:20%">
          <table data-dojo-type="dojox.grid.DataGrid" data-dojo-id="grid"  id="grid" data-dojo-props="rowsPerPage:'5', rowSelector:'20px'" style="height:100%;">
           <thead>
            <tr>
              <th field="WARRANT_NU" width="5%">Warrant #</th>
              <th field="LAST_NAME" width="10%">Last Name</th>
              <th field="FIRST_NAME" width="5%">First Name</th>
     <th field="FULL_ADDRE" width="15%">Address</th>
     <th field="ZIPCODE" width="5%">Zip</th>
     <th field="CASE_NUMBE" width="5%">Case #</th>
     <th field="OFFENSE_CO" width="5%">Offense Code</th>
     <th field="CHARGE_DES" width="15%">Charge Description</th>
            </tr>
           </thead>
        </table>
      </div>[/HTML]

Any help would be appreciated. I'm trying to learn this API and javascript and could really use some direction.
Thanks in advance.

Outcomes