Use Parameter of Choice List for GP Service

3032
10
05-26-2011 03:58 AM
Stefan_Arndt
Esri Contributor
Hey everybody,

i'm trying to implement a flex web application, which uses a geoprocessing service.
This GP Service needs a FeatureLayer/FeatureDataSet as input, before it can run.

I tried different ways to deliver the parameter, but it doesn't work.
Attached you'll find my code. I hope that somebody can find the mistake.
Probably the mistake is in this line:
var params:Object = "http://wk2658/ArcGIS/rest/services/scotturb/FeatureServer/0":featureSet;


Is it possible to use a file out of the local file system of the webserver?
Additionally i have uploaded 4 Layers in the MapDocument together with the Toolbox/GP Service, so as you can see in the screenshot i have a choice list.
How can i choose one layer of the choice list and forward this to the GP Service ?

And most important question: What i am doing wrong? 🙂


Best regards
Stefan
0 Kudos
10 Replies
by Anonymous User
Not applicable
Original User: ibespalov

screen1.png contains all information you need to submit jobs

your parameter name is "Feature_Layer" and its value is one of presented in list of choice and its type is GPString

var paramName:String = "Feature_Layer";
var paramValue:String = "scotturb_3lines_03052011";

var params:Object = { paramName: paramValue };



var params:Object = "http://wk2658/ArcGIS/rest/services/scotturb/FeatureServer/0":featureSet;

:confused:

Who teached you to do it so?


Do you now anything about ArcGIS API for Flex Samples (6 GP tasks samples)

You can find very helpful information about ArcGIS Server REST API (with samples) http://yourservername/ArcGIS/SDK/REST/index.html?gpserver.html

Good luck.
0 Kudos
Stefan_Arndt
Esri Contributor
Dear Ivan,

thank you a lot for your answer!
Nobody told me to do it like that, i tried to learn it for myself the last days and weeks.
I had a look at all the samples, watched some Tutorial-videos and read the affected API pages, but you saw the result 🙂
Even if it not looks like this, i spent already 1-2 Weeks on this problem.

So i was very happy to read your post and excited to try it out, but sadly it's still not working.
When i just enter the ValueName in the submitJob REST Service Directory (see 19.png) it works perfectly.
But when i click on the button in my widget, nothing happens.

I Added an Example-Alert to see if the function is called and the end of it is reached, this was successfull.

Is the order of the code correct? "fx:Script", then "fx:Declarations" and then the viewer:WidgetTemplate ? ( Full code attached: schematics_widget.txt).

You told me that the type is "GPString" like i can see it in the screen1.png, but you wrote just "var paramName:String" ? Why? After i tried to change String in GPString there was an error, so i think your code was correct.

:confused:
0 Kudos
by Anonymous User
Not applicable
Original User: ibespalov

...
private function gp_jobCompleteHandler(event:GeoprocessorEvent):void
{
    if (event.jobInfo.jobStatus == JobInfo.STATUS_SUCCEEDED)
    {
        // your output parameter name find in screen1.png !!!NOT Display name!!!
        gp.getResultData(gp.submitJobLastResult.jobId, "output_diagram_name");
    }
    else
    {
        // do something
    }
}

private function gp_getResultDataCompleteHandler(event:GeoprocessorEvent):void
{
    if (event.parameterValue)
    {
        // get your output result here
        dataUrl = String(event.parameterValue.value.url);
     
        if (!dataUrl)
        {
            Alert.show(emptyResultsLabel, wTemplate.widgetTitle);
            return;
        }

        Alert.show(saveDataFileLabel, wTemplate.widgetTitle, Alert.YES | Alert.NO, null, alert_ClickHandler);
    }
    else
    {
        Alert.show(emptyResultsLabel, wTemplate.widgetTitle);
    }
}

private function gp_faultHandler(event:FaultEvent):void
{
    // do something
}

private function alert_ClickHandler(event:CloseEvent):void
{
    if (event.detail == Alert.YES)
    {
        // do something
    }
}
      
]]>
</fx:Script>
 
<fx:Declarations>   
    <esri:Geoprocessor id="gp"
            url="http://wk2658/ArcGIS/rest/services/GP/GP/GPServer/server_schematic_model"
            showBusyCursor="true" 
            fault="gp_faultHandler(event)"
            getResultDataComplete="gp_getResultDataCompleteHandler(event)"
            jobComplete="gp_jobCompleteHandler(event)"/>
</fx:Declarations>


This is not my source code. This is part of DataExtractWidget.mxml source code in last Flex Viewer changed by me.

Some times ago I did small project (used GP service) based on flex viewer code - it works fine.

You must read more ESRI help and explore API reference to implement your Geoprocessor result handler.

Try to use Fiddler (for IE) or Firebug (for FF) to see actions on the background of you application (sometime it helps).
0 Kudos
Stefan_Arndt
Esri Contributor
Hey Ivan!

Thanks again!
I think most of the code is very usefull for a real application, but in my case i would like to keep it as simple as possible. Just submit the Job in the most simple Code as possible. But of course i'm very thankful of this and i tried it and edited it but the error was the same as shown below.

But the Hint with Firebug was a very good idea!
I found out that the outgoing request looks like
http://wk2658/ArcGIS/rest/services/GP/GP/GPServer/server_schematic_model/submitJob?paramName=scotturb%5Flines%5Fida%5Fhalf%5Ftest&f=json

So i can see that the Parameters are correct.

But the Response of the server is not correct. It says:
{"error":{"code":500,"message":"GPTask 'server_schematic_model' does not exist or is inaccessible.","details":[]}}


I'll try to figure out why.
If somebody has an idea in the meanwhile: I'm amenable to advices
0 Kudos
by Anonymous User
Not applicable
Original User: ibespalov

No, params are not correct!

Something wrong.

.../wk2658/ArcGIS/rest/services/GP/GP/GPServer/server_schematic_model/submitJob?paramName=scotturb%5Flines%5Fida%5Fhalf%5Ftest&f=json

must be something like:

.../wk2658/ArcGIS/rest/services/GP/GP/GPServer/server_schematic_model/submitJob?Feature_Layer=scotturb%5Flines%5Fida%5Fhalf%5Ftest&f=json
0 Kudos
Stefan_Arndt
Esri Contributor
YES! You're right!
When i enter this link in my Browser it works!
Thank you very very much for you help!
0 Kudos
by Anonymous User
Not applicable
Original User: ibespalov

Very good.

Note, what this url:
.../wk2658/ArcGIS/rest/services/GP/GP/GPServer/server_schematic_model/submitJob?Feature_Layer=scotturb%5Flines%5Fida%5Fhalf%5Ftest&f=json


must be the same with url you submit job in 19.png (your earler posted image)
0 Kudos
Stefan_Arndt
Esri Contributor
But very strange that the URL was not created correctly. Difficult to find this error. Because the code looks correct.
 var paramName:String = "Feature_Layer";
 var paramValue:String = "scotturb_lines_ida_half_test";
 var params:Object = { paramName : paramValue };


But when i manually replace the parameters it works:

 
         var params:Object = { "Feature_Layer" : "scotturb_lines_ida_half_test" }; 


Otherwise the first Variable in the braces {} is not  replaced by the Variable.
This is the reason why there was "paramName" instead of "Feature_Layer" in the Request.
When i switch paramName and paramValue the "FeatureLayer" is replaced corretly, but paramValue not any more.
Strange, but i think this is not a big problem any more.
0 Kudos
Stefan_Arndt
Esri Contributor
Hi,

just in addition to my last problem a little question:

I've already shown you my function, which uses a parameter out of the coice list:
private function generateDiagram():void
   {   
    var paramName:String = "Feature_Layer";
    var paramValue:String = "scotturb_lines_ida_half_test";    
    var params:Object = { paramName : paramValue };     
    gp2.submitJob(params);
   }


And it works.

But when i want to use a shapefile, which is not in the choice list (screen1.png from Ivan), for example with a full absolute path like "C:\arcgisserver\....\testfile" it doesnt work. But i want to learn more about geoprocessing services and would like to know why this doesn't work.

Can somebody explain it to me? What should i change (or do differently) to make it working?
Why can't he access the file?

The error message when i want to use it looks like:
"description":"The value does not exist.
ERROR 000732: Input locations: Dataset C:/arcgisserver/arcgisinput/testfile does not exist or is not supported"
0 Kudos