psrapsar

Please help me in working with find task.........urgent

Discussion created by psrapsar on Apr 2, 2010
Latest reply on Jun 22, 2012 by bebeo05
I am getting the following error.

dojo.io.script.jsonp_dojoIoScript2._jsonpCallback({"error":{"code":500,"message":"Object reference not set to an instance of an object.","details":[]}});

my code is

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=7" />
    <title>Display Find Task results in Dojo DataGrid</title>
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/1.6/js/dojo/dijit/themes/tundra/tundra.css">
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/1.6/js/dojo/dojox/grid/resources/Grid.css">
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/1.6/js/dojo/dojox/grid/resources/tundraGrid.css">

    <script type="text/javascript">
      djConfig = {
        parseOnLoad:true
      }
    </script>

    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=1.6"></script>
    <script type="text/javascript">
      dojo.require("esri.map");
      dojo.require("dojox.grid.DataGrid");
      dojo.require("dojo.data.ItemFileReadStore");
      dojo.require("esri.tasks.find");

      var findTask, findParams;
      var map, startExtent;
      var grid, store;

      function init() {
        dojo.connect(grid, "onRowClick", onRowClickHandler);
        esriConfig.defaults.io.proxyUrl = "/arcgisserver/apis/javascript/proxy/proxy.ashx";
        esriConfig.defaults.io.alwaysUseProxy = false;

        //Create map and add the ArcGIS Online imagery layer
        //startExtent = new esri.geometry.Extent(-528033.658294103, 1474077.71365155,-527667.738812264, 1474266.89111324, new esri.SpatialReference({wkid:4326}));
        map = new esri.Map("map", { extent: startExtent });
        var streetMapLayer = new esri.layers.ArcGISTiledMapServiceLayer("http://apptest/ArcGIS/rest/services/Ij/MapServer");
        map.addLayer(streetMapLayer);
  
        //Create Find Task using the URL of the map service to search
        findTask = new esri.tasks.FindTask("http://apptest/ArcGIS/rest/services/Ij/MapServer");

        //Create the find parameters
        findParams = new esri.tasks.FindParameters();
        findParams.returnGeometry = true;
        findParams.layerIds = [0];
//        findParams.out
        findParams.searchFields = ["STATENAME"];
      }

      function doFind() {
      debugger
        //Set the search text to the value in the box
        findParams.searchText = dojo.byId("pin").value;
        findTask.execute(findParams,showResults)
      }

      function showResults(results) {
      debugger
      alert(results);
        //This function works with an array of FindResult that the task returns
        map.graphics.clear();
        var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_NULL, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 2), new dojo.Color([0,0,0,0]));

        //Create items array to be added to store's data
        var items = []; //all items to be stored in data store
        for (var i=0, il=results.length; i<il; i++) {
          items.push(results[i].feature.attributes);  //append each attribute list as item in store
          var graphic = results[i].feature;
          graphic.setSymbol(symbol);
          map.graphics.add(graphic);
        }

        //Create data object to be used in store
        var data = {
          identifier: "OBJECTID",  //This field needs to have unique values
          label: "OBJECTID", //Name field for display. Not pertinent to a grid but may be used elsewhere.
          items: items
        };

         //Create data store and bind to grid.
        store = new dojo.data.ItemFileReadStore({ data:data });
        debugger
        grid.setStore(store);
        grid.setQuery({OBJECTID: '*' });

        //Zoom back to the initial map extent
        map.setExtent(graphic.geometry.getExtent());

      }

      //Zoom to the parcel when the user clicks a row
      function onRowClickHandler(evt){
        var clickedTaxLotId = grid.getItem(evt.rowIndex).OBJECTID;
        var selectedTaxLot;
        for (var i=0, il=map.graphics.graphics.length; i<il; i++) {
          var currentGraphic = map.graphics.graphics[i];
          if ((currentGraphic.attributes) && currentGraphic.attributes.OBJECTID == clickedTaxLotId){
            selectedTaxLot = currentGraphic;
            break;
          }
        }
        var taxLotExtent = selectedTaxLot.geometry.getExtent();
        map.setExtent(taxLotExtent);
      }

      dojo.addOnLoad(init);
    </script>
  </head>
  <body class="tundra">
    Pin Code: <input type="text" id="pin" size="60" value="" />
    <input type="button" value="Search" onclick="doFind();" /><br />
    <br />
    <div id="map" style="width:600px; height:300px; border:1px solid #000;"></div>
     <table dojoType="dojox.grid.DataGrid" jsid="grid" id="grid" rowsPerPage="5" rowSelector="20px" style="height:300px; width:600px">
      <thead>
        <tr>
          <!--<th field="TLID">Tax lot ID</th>
          <th field="OWNER1">Owner 1</th>
          <th field="OWNER2">Owner 2</th>
          <th field="OWNER3">Owner 3</th>
          <th field="TOTALVAL">Total value</th>-->
          <th field="OBJECTID">OBJECTID</th>
        </tr>
      </thead>
    </table>
  </body>
</html>

Outcomes