Beginner: findTask does not seem to work

Discussion created by cgeiger on Sep 23, 2011
Latest reply on Sep 23, 2011 by DSwingley-esristaff
I have combined parts of two sample scripts: query and find.  The query (click a point to highlight the polygon that was clicked in and open an attribute pop-up) works fine.  The find (type a place name in a text box and click an input button to re-symbolize the found point) does not.  I would greatly appreciate another pair of eyes on this.  The map service layers are correct and the fieldnames are correct.  Place names (such as Coatesville or Lancaster) in the attribute table are in title case.  The relevant part of my HTML/JavaScript code is pasted here:

    <script type="text/javascript">

      var map;
      var featureSet, queryTask, query;
      var findPlace, findParams;

      function init() {
          //Map's initial extent:
        var initExtent = new esri.geometry.Extent({"xmin":-8980000,"ymin":4750000,"xmax":-8300000,"ymax":5260000,"spatialReference":{"wkid":102100}});
          //Create the map:
        map = new esri.Map("mapDiv",{extent:initExtent});

          //Creates the shaded relief basemap
        var basemapURL = "";
        var basemap = new esri.layers.ArcGISTiledMapServiceLayer(basemapURL);

          //Add the landforms layers
        var paMapURL= "";
        var paMap = new esri.layers.ArcGISDynamicMapServiceLayer(paMapURL, {"opacity": 0.4});

          //Add the places layers
        var paPlacesURL= "";
        var paPlaces = new esri.layers.ArcGISDynamicMapServiceLayer(paPlacesURL, {"opacity": 0.8});
          //Create the find task
        findPlace = new esri.tasks.FindTask(paPlacesURL+"/");
          //Create the find paramaters
        findParams = new esri.tasks.FindParameters();
        findParams.returnGeometry = true;
        findParams.layerIDs = [0];
        findParams.searchFields = ["AREANAME"];

          //Listen for Click event:       
        dojo.connect(map, "onClick", doQueryTask);
          //Listen for infoWindow Hide event:
        dojo.connect(map.infoWindow, "onHide", function() {;});

          //Build query task:
        queryTask = new esri.tasks.QueryTask (paMapURL+"/2");
          //Build query filter:
        query = new esri.tasks.Query();
          query.outSpatialReference = {"wkid":102100};
          query.returnGeometry = true;
          query.outFields = ["PROVINCE", "SECTION"];
      function doQueryTask(evt)  {
        featureSet = null;
        //onClick event returns the point where the user clicked on the map as "evt":
        query.geometry = evt.mapPoint;
        //Executing the task:
        queryTask.execute(query, function(fset) {
          if (fset.features.length === 1) {
      function showFeature(feature,evt)  {;

          //Set the symbol:
        //var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 2), new dojo.Color([255,255,0,0.5]));
        //Set symbology
        var areaStyle = esri.symbol.SimpleFillSymbol.STYLE_SOLID;
        var areaOutlineStyle = esri.symbol.SimpleLineSymbol.STYLE_SOLID;
        var areaOutlineColor = new dojo.Color([244,0,0]);
        var areaColor = new dojo.Color([220,220,0,0.5]);
        var areaOutline = new esri.symbol.SimpleLineSymbol(areaOutlineStyle, areaOutlineColor, 2);
        var areaSymbol = new esri.symbol.SimpleFillSymbol(areaStyle, areaOutline, areaColor);

          //Construct infoWindow
        var attr = feature.attributes;
        var title = "<center>PA Landforms</center>";
        var content = "<font face='tahoma' color='red'><b>Landform Region:  </b></font>"+attr.PROVINCE + "<br /><font face='tahoma' color='red'><b>Subregion:  </b></font>"+attr.SECTION;;
      function execute(searchText) {
        //Set the search text
        findParams.searchText = searchText;
        findPlace.execute(findParams, showResults);
      function showResults(results) {
        //Set symbology
        window.alert("Im here");
        var pointStyle = esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE;
        var pointOutlineStyle = esri.symbol.SimpleLineSymbol.STYLE_SOLID;
        var symbolColor = new dojo.Color([255,0,0]);
        var lineSymbol = new esri.symbol.SimpleLineSymbol(pointOutlineStyle,symbolColor,1);
        var pointSymbol = new esri.symbol.SimpleMarkerSymbol(pointStyle,10,lineSymbol,symbolColor);
        //find results returns an array of findResult;
        var dataForSymbol = [];
        //Build an array and add each found place to the map
        dojo.forEach(results, function(result) {
          var graphic = result.feature;
          dataForSymbol.push([result.layerName, result.foundFieldName, result.value]);

  <body class="claro">
    <div id="content" dojoType="dijit.layout.BorderContainer" design="headline" gutters="true" style="width: 100%; height: 100%; margin: 0;">
      <div class="searches" dojotype="dijit.layout.BorderContainer" region="top" style="height:30px;">
        <h1>Pennsylvania Landform Finder</h1>
      <div id="legendPane" dojoType="dijit.layout.ContentPane" title="Legend" selected="true" region="right">
        <div id="legendDiv">
          <h3>Place Name:</h3>
          <input type="text" id="searchText" value="Philadelphia" /><br />
          <input type="button" value="Find It" onclick="execute(dojo.byId('searchText').value);"/><br />
          <p><h4>To find the landform region in which a place is located, type the name of the place in the box
          above and click on "Find It."  When the place is highlighted, zoom the map closer to it, and then
          click on the place; the landform area surrounding it will be highlighted and the identifying information will pop up.</h4></p> 
      <div id="mapDiv" dojoType="dijit.layout.ContentPane" region="center" style="overflow:hidden;"></div>