Getting results from submitJob:

5269
16
04-28-2010 01:26 PM
DorothyMortenson
Deactivated User
Hello,
I have a gp.submitJob that works, as in it goes and runs the job as expected. It creates several GIS files. (this works if I just run the gp.submitJob(params)).

Now I want to get the results to come back (get a specific featureclass, called wshed_results.gdb\wshed_1)

I don't really know what I'm doing, but here is what I have so far.  I am getting a "1067: Implicit coercion of a value of type Function to an unrelated type mx.rpc:IResponder." error.

Any ideas on what I really should be doing?
Dorothy

//===============
...
                    gp.submitJob(params, completeCallback, statusCallback);
                   
                }



private function statusCallback(jobInfo):void
{
  Alert.show(jobInfo.jobStatus);
}
private function completeCallback(jobInfo):void
{
  gp.getResultData(jobInfo.jobId, result.value.features, displayResult);

}

private function displayResult(result, messages):void
{
    var features = result.value.features;
    var graphic:Graphic = new Graphic(features);
     for each (var graphic:Graphic in event.executeResult.parameterValues[0].value.features)
     {
      graphic.symbol = watershedSimpleFill;
       myGraphicsLayer.add(graphic);
     }

/================
Tags (2)
0 Kudos
16 Replies
RichardBetts
Deactivated User
Hi

Heres what I'm using. Hopefully this might help?
   
         gp.addEventListener(GeoprocessorEvent.JOB_COMPLETE, onJobComplete);
         gp.submitJob( params );

function onJobComplete(event : GeoprocessorEvent):void
    {
    gp.addEventListener(GeoprocessorEvent.GET_RESULT_DATA_COMPLETE, onGetResult);
    gp.getResultData(event.jobInfo.jobId, "actual name of the output parameter");
    }
function onGetResult(event : GeoprocessorEvent):void
    {
       var pv:ParameterValue = event.parameterValue;
       var fs:FeatureSet = pv.value as FeatureSet;           
       etc
          }                 

Cheers

Richard
0 Kudos
DorothyMortenson
Deactivated User
Thanks Richard.
I'm a little confused on how to set up the output parameter. Can you explain?
Dorothy
0 Kudos
RichardBetts
Deactivated User
Dorothy, 

If you take a look at the REST endpoint for your gp task (http://servername:8399/arcgis/rest/services etc), you should see information about all of the parameters your task uses.

If you find a parameter with a direction of  'esriGPParameterDirectionOutput', then you should be able to retrieve the output in your Flex app using the code I suggested previously. You need to be sure to use the exact name of the parameter as listed in the REST endpoint, rather than the display name.

Hope that makes sense and works for you.

Richard
0 Kudos
DorothyMortenson
Deactivated User
Thanks Richard,

I have a python script I am running in a toolbox.  I have set a parameter called "output" and made it "Derived". I didn't set any of the other criteria for this particular parameter, such as default, etc.

I'm not quite getting how I assign the value I want from my python script to the "output".  I've tried this line at the end of my script:

gp.setParameterAsText(1,watershed)

where "watershed" is a polygon feature class as a result of the python script processing. It doesn't work.

If I had several results I wanted to use (a text file, a couple of feature classes), how do I tell which one is which?

I really appreciate your help on this.
Dorothy
0 Kudos
RichardBetts
Deactivated User
No problem, although I hope I'm not pointing you in the wrong direction...

My gp service was created from a model (I'm not using python). The final stage in my model is a dissolve operation which produces a feature class as the output (in my case a shape file).
When I publish my model to server and run from my application I can actually see the shape file generated in the server arcgisjobs directory, inside the directory with the relevant job id. This directory gets created with a unique identifier each time you submit the job from your application. 
It might be worth checking here to make sure your gp task is running properly and producing the output you expect. 

Its then a case of checking the REST endpoint for the task to see if the output parameter appears here and using the exact same name to retrieve the data in your application.

However, I'm not sure if this method will work if the output is not a feature class? Someone else might be able to help here. 

Its also worth remembering to refresh your REST cache each time you re-publish your model, something I often forget to do!

Richard
0 Kudos
seanlo
by
Emerging Contributor
Hi Dorothy,

I'm writing my 3rd python script which outputs raster on the Flex viewer (via geoprocessing).

For the results, simply use the rest services. Look at the output result name. Use THAT result name.

Let me elaborate in case i'm a bit too brief:
1) Use the rest services. IE: http://sean:8399/arcgis/rest/services/CCM/GPServer/MCAClip/submitJob
2) Enter the values there manually. Click submit job.
3) Look at the name of the result. In my case, i received:
Results:
ClipMCA

4) Use ClipMCA as the name of that result to add to your layer. In my case (rasters) i used:
   var imageParameters : ImageParameters = new ImageParameters();  
   var myImageLayer :GPResultImageLayer = gp.getResultImageLayer(event.jobInfo.jobId,"ClipMCA",imageParameters)
   myImageLayer.id="ClipMCA";   //when minimising the map, remove this layer name.
   map.addLayer(ClipMCA);

upon gp completion.

Hope that helps you!

Sean.
0 Kudos
DorothyMortenson
Deactivated User
Thanks Sean.

So, what did you do in Python to set the output to be ClipMCA?
* Did you set this as a Parameter in the ArcCatalog Properties?
* Did you code something in Python ?

I've tried what you had recommended, run the submit job from the URL. It just says it succeeded, but it doesn't give me a specific output.

Dorothy
0 Kudos
DorothyMortenson
Deactivated User
Ok, I'll table that question for now.

I made a test model builder that now works and shows the results when testing the rest service.  it does not show up in my map application, however.

What does the rest of your code look like, as it pertains to the ArcGISDynamicMapServiceLayeror a GraphicsLayer?
Did you have to create a special ArcGISDynamicMapServiceLayer for this?

Thank you.
Dorothy
0 Kudos
seanlo
by
Emerging Contributor
Hey dorothy,

In the geoprocessing tool, select add to display for the final result, and click model parameter. (For some reason this has to be turned on to display)

1) Run the model once, make sure it displays on the MXD.
2) Remove that layer.
3) Click and DRAG the model into the layer Table of content. (This sets the layer as a map result service)
4) Untick the raster result under the layer name of that model you just dragged in.

Now, add this as a geoprocessing service, and go do the rest thing again. You should be able to see the name. Here's a screenshot to illustrate my point:
http://img541.imageshack.us/i/georesult.jpg/

Sean
0 Kudos