Returning a text value from a spatial query

Discussion created by sondickerson on Feb 1, 2013
Latest reply on Feb 4, 2013 by sondickerson
I need to return a text value so that it can be used in Crystal Reports.  The report will access the app by appending the coordinates of a known location as parameters to the app url.

for example:  http://servername/spatialservices/getstate.html?-11920113.271*5345577.536

I'd want the html page to return the name of the state where the given coordinates reside.
The following code works in retrieving the state,  I just don't know how to get it to pass an object that Crystal reports can read as text. 

Here's the code that I have.  Thank you for any help.



<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9"/>


  <script type="text/javascript" src=""></script>
    <script type="text/javascript">

    function init(){
       var webParams =;
      //format  ?x*y
      //parse out info that comes after the ?
      XYString = webParams.substr(1).split('*');
      XString = XYString[0];
      YString = XYString[1];

      //set xy to preset values to verify the process
      //Wyoming -11920113.271*5345577.536
      //Wisconsin  -10045094.029*5622569.015
      //Alaska  -17076416.186*9905283.420
      //Alabama -9618953.292*3896699.031

      if ((XString != null) && (YString != null)) {
              fimStandQueryTask = new esri.tasks.QueryTask("");
            featureQuery = new esri.tasks.Query();
            featureQuery.returnGeometry = false;
            featureQuery.spatialRelationship = esri.tasks.Query.SPATIAL_REL_WITHIN;
            featureQuery.outFields = ["NAME"];
            featureQuery.geometryType = "esriGeometryPoint";
            featureQuery.where = "1=1";

            var XY = new esri.geometry.Point(XString, YString, new esri.SpatialReference({ wkid: 102100 }));
            featureQuery.geometry = XY;
            fimStandQueryTask.execute(featureQuery, showResults);
        } else {


    function showResults(featureSet) {

        var s = "NA";
        if (featureSet != null) {
            if (featureSet.features.length > 0) {
                var featureAttributes = featureSet.features[0].attributes;
                for (att in featureAttributes) {
                    s = featureAttributes[att];

        //Build the appropriate data object for our data component
        var data = { "identifier": "StateName", "items": s };
        return data.items;