Select to view content in your preferred language

Get result from asynchronous geoprocessing task

3116
3
Jump to solution
06-13-2014 10:48 PM
NeoGeo
by
Frequent Contributor
I am using this asynchronous geoprocessing task example to rewrite an existing Flex widget to use a geoprocessing service instead of a non-ESRI REST service:
https://developers.arcgis.com/flex/sample-code/asynchronous-geoprocessing.htm

The geoprocessing task submits successfully and according to Fiddler, the service returned the correct data in single output parameter named "myresults" which is a string (containing json data).

At this point, Flex just hangs with a busy cursor apparently in gp_getResultDataCompleteHandler() because everything I have tried using event.parameterValue to get the result from the service has failed. Even just a plain Alert.show with event.parameterValue seems to be ignored.  Can anyone tell me how to get the service result from the parameter and stuff it into an array so that I can then do something like this:

    if (results != null && myresults.records != null)     {      var records:Array = results.records;      buildMyString(records);      var recordsList:ArrayList = new ArrayList(records);      dgResults.dataProvider = recordsList;      showStateResults();     }



This was the URL of the last request : http://<servername>/arcgis/rest/services/Geoprocessing_Services/MyService/GPServer/MyScript/jobs/<jobid>/results/myresults?f=json&returnType=data

The data returned by the service looks like this:
{"paramName":"myresults","dataType":"GPString","value":{"records": [{"layer": "Wolves", "value": "-999"}, {"layer": "Coyotes", "value": "-999"}, {"layer": "Dingos", "value": "5.44373945354"}]}}

The relevant portions of the code are:
  <esri:Geoprocessor id="generateStatsGP"          url="{genURL}"          fault="gp_faultHandler(event)"          getResultDataComplete="gp_getResultDataCompleteHandler(event)"          jobComplete="gp_jobCompleteHandler(event)"          outSpatialReference="{map.spatialReference}"          useAMF="false"/>        var params:Object = {"f":"json", "location":geomJSON, "locationtype":geomType,"units": distanceUnits.toUpperCase()};     generateStatsGP.submitJob(params);     CursorManager.setBusyCursor();       private function gp_getResultDataCompleteHandler(event:GeoprocessorEvent):void    {          Output = event.parameterValue.value;     if (event.parameterValue.paramName == "myresults")     {      //Why doesn't this work?      Alert.show("Yes Virginia, paramName is myresults!");     }     if (event.parameterValue.value != null)     {      //Why doesn't this work?      Alert.show("parameterValue.value is not null");     }      CursorManager.removeBusyCursor();    }          private function gp_jobCompleteHandler(event:GeoprocessorEvent):void    {     if (event.jobInfo.jobStatus == JobInfo.STATUS_SUCCEEDED)     {      generateStatsGP.getResultData(generateStatsGP.submitJobLastResult.jobId, "myresults");     }     else     {      Alert.show(event.jobInfo.jobStatus);      CursorManager.removeBusyCursor();     }    }


Thanks!!
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
NeoGeo
by
Frequent Contributor
I could not find anything in the ESRI docs past getting the job id, but using the debugger and breakpoints was able to see the object structure and figure it out.  There was still some weirdness that just suddenly disappeared when I started deleting some comments and junk almost like the problems you get when you end up with invisible characters in xml files, so I may never know what exactly caused that, but pretty much the same code worked.  This is what I ended up with to get the data from the parameters:

   private function gp_getResultDataCompleteHandler(event:GeoprocessorEvent):void    {     if (event.parameterValue.value != null && event.parameterValue.value.records !=null)     {      var records:Array = event.parameterValue.value.records;      buildMyString(records);      var recordsList:ArrayList = new ArrayList(records);      dgResults.dataProvider = recordsList;      showStateResults();     }     clearMessage();     CursorManager.removeBusyCursor();    }

View solution in original post

0 Kudos
3 Replies
JordanBaumgardner
Frequent Contributor
Q: Are you two event handlers [gp_jobCompleteHandler | gp_getResultDataCompleteHandler ] getting called at all?
0 Kudos
NeoGeo
by
Frequent Contributor
I have confirmed that the getresultdata inside of the gp_jobCompleteHandler() executes, and see the gp results (the json string) when monitoring it in Fiddler. 

I also added a breakpoint inside of gp_getResultDataCompleteHandler() and confirmed that it also executes and all of the data is there.
0 Kudos
NeoGeo
by
Frequent Contributor
I could not find anything in the ESRI docs past getting the job id, but using the debugger and breakpoints was able to see the object structure and figure it out.  There was still some weirdness that just suddenly disappeared when I started deleting some comments and junk almost like the problems you get when you end up with invisible characters in xml files, so I may never know what exactly caused that, but pretty much the same code worked.  This is what I ended up with to get the data from the parameters:

   private function gp_getResultDataCompleteHandler(event:GeoprocessorEvent):void    {     if (event.parameterValue.value != null && event.parameterValue.value.records !=null)     {      var records:Array = event.parameterValue.value.records;      buildMyString(records);      var recordsList:ArrayList = new ArrayList(records);      dgResults.dataProvider = recordsList;      showStateResults();     }     clearMessage();     CursorManager.removeBusyCursor();    }
0 Kudos