PinnGIS

Using FindTask with ArcGIS Online Feature Service?

Discussion created by PinnGIS on Jan 12, 2013
Latest reply on Mar 18, 2013 by svakil-esristaff
Hello,

I'm trying to setup a simple search feature on one of my web apps.  I've been following this sample :http://help.arcgis.com/en/webapi/javascript/arcgis/jssamples/#sample/find_map

The problem is when I try to do a search I get this error: 'Error: Feature (ID: find) not found'

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9">
    <!--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>Find Task</title>

    <link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/js/dojo/dijit/themes/claro/claro.css">
    <link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/js/dojo/dojox/grid/resources/Grid.css">
    <link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/js/esri/css/esri.css">
    <style>
      html, body { height: 100%; width: 100%; margin: 0; padding: 0; overflow:hidden; }
      body { font-size: 0.9em; font-family: Geneva, Arial, Helvetica, sans-serif;
      } .details { font-weight: bold; } #grid { border:
      1px solid #333;}
    </style>

    <script>var dojoConfig = { parseOnLoad: true };</script>
    <script src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/"></script>
    <script>
      dojo.require("dojox.grid.DataGrid");
      dojo.require("dojo.data.ItemFileReadStore");
      dojo.require("esri.map");
      dojo.require("esri.tasks.find");
      dojo.require("dijit.layout.BorderContainer");
      dojo.require("dijit.layout.ContentPane");
      dojo.require("esri.layers.FeatureLayer");
      dojo.require("esri.IdentityManager");
      
      var findTask, findParams, map;

      function init() {
        var initialExtent = new esri.geometry.Extent({ "xmin": 12545522.8061115, "ymin": -4182250.4450148, "xmax": 14360429.0609884, "ymax": -1531704.69903858, "spatialReference": { "wkid": 102100} });
        map = new esri.Map("map", {
            extent: initialExtent,
            wrapAround180: true,
            basemap: "streets"
        });

        var url1 = "https://services1.arcgis.com/059vseHWoaYhLBFT/arcgis/rest/services/Native_Title_Claim_Boundaries/FeatureServer/0";
        var featLayer1 = new esri.layers.FeatureLayer(url1, {
            mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
            outFields: ["*"]
        });
        map.addLayer(featLayer1)

        //create find task with url to map service
        findTask = new esri.tasks.FindTask("https://services1.arcgis.com/059vseHWoaYhLBFT/arcgis/rest/services/Native_Title_Claim_Boundaries/FeatureServer/0");

        //create find parameters and define known values
        findParams = new esri.tasks.FindParameters();
        findParams.returnGeometry = true;
        findParams.layerIds = [0];
        findParams.searchFields = ["NAME", "TRIBNO"];
      }

      function execute(searchText) {
        //set the search text to find parameters
        findParams.searchText = searchText;
        findTask.execute(findParams, showResults);
      }

      function showResults(results) {
        //symbology for graphics
        var markerSymbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 10, 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 lineSymbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASH, new dojo.Color([255, 0, 0]), 1);
        var polygonSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_NONE, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color([255, 0, 0]), 2), new dojo.Color([255, 255, 0, 0.25]));

        //find results return an array of findResult.
        map.graphics.clear();
        var dataForGrid = [];
        //Build an array of attribute information and add each found graphic to the map
        dojo.forEach(results, function(result) {
          var graphic = result.feature;
          dataForGrid.push([result.layerName, result.foundFieldName, result.value]);
          switch (graphic.geometry.type) {
          case "point":
            graphic.setSymbol(markerSymbol);
            break;
          case "polyline":
            graphic.setSymbol(lineSymbol);
            break;
          case "polygon":
            graphic.setSymbol(polygonSymbol);
            break;
          }
          map.graphics.add(graphic);
        });
        var data = {
          items: dataForGrid
        };
        var store = new dojo.data.ItemFileReadStore({
          data: data
        });
        grid.setStore(store);
      }
      dojo.ready(init);
    </script>
  </head>
  
  <body class="claro">
   <div data-dojo-type="dijit.layout.BorderContainer" style="width:100%;height:100%;margin:0" data-dojo-props="design:'headline',gutters:true">
    <div class="details" data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="region:'top'" style="height:30px;">
      Native Title Group:
      <input type="text" id="searchText" value="Badimia People" />
      <input type="button" value="Find" onclick="execute(dojo.byId('searchText').value);"/>
    </div>
    <div id="map" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'center'" style="border:1px solid #000;"></div>
    <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'left'" style="width:300px;">
    <!--Refer to field by the position id, since the data doesn't have field
    names-->
    <table data-dojo-type="dojox.grid.DataGrid" jsid="grid" id="grid" >
      <thead>
        <tr>
          <th field="0" >
            Layer Name 
          </th>
          <th field="1" >
            Field Name
          </th>
          <th field="2" >
            Value
          </th>
        </tr>
      </thead>
    </table>
    </div>
   </div>
  </body>

</html>


I suspect the problem is that the layer I'm trying to search is a Feature Service hosted on ArcGIS Online?

Outcomes