Find Task on XY Event

1653
15
04-28-2011 09:46 AM
StephanieWidas
New Contributor III
I have XY data in SQL that I have added as an event layer to a map document.  That .mxd was then used to create a map service.  I can sucessfully use the Find Task in the REST services directory to find a specific record, but when I try to execute the find task using the Javascript API, it fails. 

I exported my data to a personal geodatabase and created a map service off of the new feature class.  The Find Task worked perfectly.  It works if the source data of the map service is a feature class, but fails if it is an XY event layer.  Can the Find Task be used on XY events or that a limitation of the task?  Perhaps it is just a syntax error when defining my find parameters?
     findParams = new esri.arcgis.gmaps.FindParameters();
     findParams.returnGeometry = true;
     findParams.layerIds = [0];
     findParams.searchFields = ["REQUESTID"];

     findParams.searchText = requestID;
     findParams.contains = true;
     findTask.execute(findParams, zoomToRecord);



Any help would be much appreciated.
Thanks!
~Stephanie
0 Kudos
15 Replies
HemingZhu
Occasional Contributor III
I have XY data in SQL that I have added as an event layer to a map document.  That .mxd was then used to create a map service.  I can sucessfully use the Find Task in the REST services directory to find a specific record, but when I try to execute the find task using the Javascript API, it fails. 

I exported my data to a personal geodatabase and created a map service off of the new feature class.  The Find Task worked perfectly.  It works if the source data of the map service is a feature class, but fails if it is an XY event layer.  Can the Find Task be used on XY events or that a limitation of the task?  Perhaps it is just a syntax error when defining my find parameters?
     findParams = new esri.arcgis.gmaps.FindParameters();
     findParams.returnGeometry = true;
     findParams.layerIds = [0];
     findParams.searchFields = ["REQUESTID"];

     findParams.searchText = requestID;
     findParams.contains = true;
     findTask.execute(findParams, zoomToRecord);



Any help would be much appreciated.
Thanks!
~Stephanie


XY Event layer is a temorary feature layer stored in memory or system "temp" folder. It is not persisent. Most likely your none local ArcGIS accounts (SOM, SOC, ArcGISWebServices) has no access to it and no surprise that you failed in getting findTask.  Exported as permanent feature class is the right thing to do.
0 Kudos
MikeLong
New Contributor III
There may be a way around this.  I believe I have used it in the past but it has been a while.

Use the Make Query Table tool on your table before you create your Event Layer.  This will add an ObjectID field, which is required for selections, and just may be required for the find task as well.

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000006r000000.htm

Hope it helps.

-Mike
0 Kudos
StephanieWidas
New Contributor III
Mike,
Thank you for your suggestions.  I will look into the Make Query Table tool. 
Do you know why the find task will work on the XY layer when it is executed through the REST services directory but not through the Javascript API?  I'm a little lost as to why the find task works in one but not the other.  Since it works in REST, wouldn't that mean that the ArcGIS accounts have access to it?  Or are they unrelated?
Thanks!
~Stephanie
0 Kudos
derekswingley1
Frequent Contributor
@Stess if it works via the REST endpoint, but not with JS, then there's either a bug in the JS API or a problem with your code. Can you post a more complete code sample?
0 Kudos
StephanieWidas
New Contributor III
swingley - I'm guessing it is probably something with my code! Here are a few more lines:


    function searchRequestID(requestID) {
        gmap.closeInfoWindow();
     mapExtension.removeFromMap(gOverlays);
     gmap.setCenter(new GLatLng(34.8370,-82.3658),12);
  //Clear layer definitions
  var layerDefinitions = [];
  layerDefinitions[0] = "";
  layer.setLayerDefinitions(layerDefinitions);
     gmap.closeInfoWindow();
  
     var findTask, findParams;
     findTask = new esri.arcgis.gmaps.FindTask("my map service url");
  findParams = new esri.arcgis.gmaps.FindParameters();
     findParams.returnGeometry = true;
     findParams.layerIds = [0];
     findParams.searchFields = ["REQUESTID"];
     findParams.searchText = requestID;
     findParams.contains = true;
     findTask.execute(findParams, zoomToRecord);
     mapExtension.removeFromMap(gOverlays);
 }

   function zoomToRecord(results){

     var result, attribs, feature;
  if (results == null){
   alert("nothing here");
  }
  if (results.findResults.length >0){
   var identifyContent = "Put content here </br>";
   var infoWindowOptions = {
   content:identifyContent};
   var overlayOptions = {
            strokeColor:"#FF0000",
            strokeWeight:4,
            strokeOpacity:0.75,
            fillColor:"#FF0000",
            fillOpacity:0.0};
   gOverlays = mapExtension.addToMap(results, overlayOptions, infoWindowOptions);

   for (i=0, il=results.findResults.length; i<il; i++){
    result = results.findResults;
    feature = result.feature;
    attribs = feature.attributes;
    if (attribs["Shape"] == "Polygon" || attribs["Shape"] == "Polyline"){
     var featureGeometry = result.feature.geometry[0];
     var featureBounds = featureGeometry.getBounds();
     var zoomLevel = gmap.getBoundsZoomLevel(featureBounds);
     var featureCenter = featureBounds.getCenter();
     gmap.setCenter(featureCenter, zoomLevel);
    }
    else if(attribs["Shape"] == "Point"){
     var featureGeometry = result.feature.geometry[0];
     gmap.setCenter(featureGeometry.getLatLng(), 15);
    }
   }
   if (results.findResults.length > 1){
    alert("There are " + results.findResults.length + " locations throughout the city.");
   }
  }
  else if (results.findResults.length == 0){
   alert("This project does not have a map location. For a project description, click on the information button in the table.");
  }

    }


As part of my troubleshooting, I added a line in there that checks if any results are returned and alerts me if nothing is found.  It's not returning any results...I get the "nothing here" message. 
I have attached a screenshot that shows that I get results when running the find task from REST.  I see that it has a FeatureID of -1.  Would that cause a problem?
Thank you for your help!
0 Kudos
StephanieWidas
New Contributor III
I was hoping that a fresh mind after the weekend would help, but I'm still stumped.

I've used map services based on XY events in Flex without a hitch.  I can query, etc. in my Flex apps and I can execute the Find Task just fine from the REST endpoint.  This leads me to believe that it is a problem related to the javascript API or something along those lines. 

I used Fiddler and I get the following when I try to execute the Find Task from my app:

esri.arcgis.gmaps._RestRequest._requestQueue.ArcGISJson_40631967163708915._callback({"error":{"code":500,"message":"Object reference not set to an instance of an object.","details":[]}});

Perhaps that is a clue to the problem, but I don't know what to do with it.  Is this problem something that can be fixed (an error in my code, etc.)?  Or is a Find just not going to work in Javascript (in other words I just need to scrap the find or switch to Flex)?

Thanks again!
~Stephanie
0 Kudos
derekswingley1
Frequent Contributor
Which version of the Flex API were you using? And which version of ArcGIS Server?
0 Kudos
StephanieWidas
New Contributor III
We are running ArcGIS Server 9.3.1. 

We have a couple different Flex apps using versions 1.2 and 1.3 of the ArcGIS for Flex API.  We have used map services built on XY event layers in the past without any problems.  For example, we use the Live Layer widget on XY layers -- that widget runs a query task and returns results just fine.  Just to make sure there wasn't something wrong with the map service that I'm using in this Javascript project, I used it in a Live Layer widget in a test Flex app.  It worked fine, so there shouldn't be anything wrong with the map service itself.

Thank you!
~Stephanie
0 Kudos
derekswingley1
Frequent Contributor
Hmm...is your endpoint publicly accessible? I'm not sure how helpful I can be w/o access to test for myself. If it's not available publicly, I would say it's time to talk to tech support.
0 Kudos