bryankaraffa

FindTask reporting "unable to complete operation"

Discussion created by bryankaraffa on May 7, 2012
Latest reply on May 7, 2012 by bryankaraffa
Hi all,

I am trying to figure out what is wrong with my FindTask script.. I used a sample and made changed 2 lines where appropriate and it is not working as intended.....  I really am at a dead end here and was hoping for your help..
"
Ultimately, I'd like to be able to type "ANTH 121" or any other class in the field and have it return the values as it should but I just get the error "Error: Unable to complete  operation."

My code:
[HTML]<!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,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>Simple Find</title>
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.8/js/dojo/dijit/themes/claro/claro.css">
    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.8"></script>
    <script type="text/javascript">
      dojo.require("esri.map");
      dojo.require("esri.tasks.find");

      var find, params;
      function init() {
        find = new esri.tasks.FindTask("http://ags2.geog.ucsb.edu/ArcGIS/rest/services/bldgRoomLocator2012May07/MapServer");
        params = new esri.tasks.FindParameters();
        params.layerIds = [1];
        params.searchFields = ["courseTitle","fullTitle"];
      }

      function doFind() {
        params.searchText = dojo.byId("searchText").value;
        find.execute(params, showResults, alert);
      }

      function showResults(results) {
        var result, attribs;
        var s = ["<table border=\"1\"><thead><tr style=\"background-color:#ccc;\"><td>Course Title</td><td>Full Title</td><td>Primary Title</td><td>Location</td></tr></thead><tbody id=\"states\">"];
        dojo.forEach(results,function(result){
          attribs = result.feature.attributes;
           s.push("<tr><td>" + attribs.courseTitle + "</td><td>" + attribs.fullTitle + "</td><td>" + attribs.primaryTitle + "</td><td>" + attribs.location + "</td></tr>");
        });
        s.push("</tbody></table>");
        dojo.byId("tbl").innerHTML = s.join("");
      }

      dojo.addOnLoad(init);
    </script>

  </head>
  <body class="claro">
    Search by Course Title: <input type="text" id="searchText" size="40" value="ANTH 121" />
    <input type="button" value="Find" onclick="doFind()" />

    <div id="tbl"></div>

  </body>
</html>[/HTML]

Outcomes