Select to view content in your preferred language

Optional versus Required GP Parameters for Python Script Tool

2302
4
08-10-2011 08:40 AM
RussCoffey
Occasional Contributor
I published a Python script tool as a GP service in ArcServer.  This script has a number of parameters (17 at the moment and possibly more as time goes by).  Only two parameters are required.  However, when I call the GPService from Silverlight (in C#), I have to specify ALL of the parameters, even the "optional" ones.  If I do not pass a value for ALL parameters, the task fails with "ESRI.ArcGIS.Client.Tasks.ServiceException: Error Submitting Job."  If I do pass a value for each parameter, the job runs fine.

Here's my issue: This service will be called from many Silverlight/ArcServer apps, and I would like to be able to add another optional parameter without breaking every app that calls the service.  By adding a parameter, I will be effectively requiring each developer to republish their code to include a parameter their app probably doesn't care about.

Do I misunderstand the significance of setting a parameter to Optional versus Required?

(I will also post this in the Geoprocessing forum.)

Thanks for any advice/suggestions.
0 Kudos
4 Replies
JMcNeil
Deactivated User
Does you model fail in ArcMAP when you don't provide an optional input?  I'm betting it does, which means you shouldn't have it set to optional or if you want it to be set to optional you need to set a default parameter input for each parameter that is set to optional.  WIth the default parameter set in the model(tool) then it won't fail and your users won't be forced to enter a value.


Here's my issue: This service will be called from many Silverlight/ArcServer apps, and I would like to be able to add another optional parameter without breaking every app that calls the service. By adding a parameter, I will be effectively requiring each developer to republish their code to include a parameter their app probably doesn't care about.


JUst give this parameter a hard coded default in the model/tool and you should be fine.

J
0 Kudos
RussCoffey
Occasional Contributor
Thanks for the idea, esrijay.  I did as you suggested and added default values for all parameters, but the GPTask still fails if my Silverlight app C# code does not create a GPParameter for each tool parameter.

It was a good suggestion, but you may have misunderstood my issue because you referred to running the tool in ArcMap.  I am not running the tool in ArcMap.  I am calling the GP service from Silverlight, C#, and it works fine as long as I specify a value for ALL parameters, even the optional ones.

Here is the C# code I am using for setting up the GP Task:

            Geoprocessor gpTask = new Geoprocessor("http://ARCSERVERDEV/ArcGIS/rest/services/ETS/GP_Tools/GPServer/Generic Web Printing");

            List<GPParameter> gpParameters = new List<GPParameter>();
            gpParameters.Add(new GPString("Calling_App", "MeterRouting"));
            gpParameters.Add(new GPString("MXD_Name", "Meter_Route_Mapping"));
            gpParameters.Add(new GPString("Data_Frame", "Main_Map_Frame"));
            gpParameters.Add(new GPString("User_Name", UserName));
            gpParameters.Add(new GPString("Layers_to_Update", "Meters;Route_Label"));
            ........ and so forth for all of the parameters

My question is why do I have to provide a value in code for all parameters, even the "optional" ones...
(Or, hopefully, maybe I am missing something that would allow me to not have to specify a value for optional parameters...?)

Thanks again...............j.russ
0 Kudos
JMcNeil
Deactivated User
j.russ

I understand your are calling the GP service from Silverlight, C# but it should work in ArcMAP first before you try in Server and it sounds like you can get to work in both but you can't get it to work in either if you don't provide a parameter value.  When you don't provide a Parameter value in ArcMAP does it work?  If not then the Optional setting makes no sense and it shouldn't be set to optional. 

The Optional setting seems strange to me and I guess as you pointed out in your first post this might be better suited for the GP forums because it that is where your issue is. 

A very  Basic example of a simple GP model/task is One layer, An Expression feeding into the Select Layer By Attribute tool and producing a selection of the layer based on the expression (attribute query).  If you create this model that does this one simple task (Select Layer by Attribute) you will notice you can set your expression parameter (the attribute select statement) to optional, which makes no sense because how will the model know what to select if the expression is not present??? 

To me the optional setting should be controlled by the creator of the Model and not by what ESRI/ArcMAP allows.  What I mean is if ArcMAP/ESRI lets one set an parameter to optional that doesn't necessary mean it is truly optional.  This sounds strange but I guess I really don't understand what optional means either???:confused: Clearly in the example I just provided there is no way the expression should be optional. 

Sorry I wasn't able to help, maybe the GP team can let you in on a secret and if they can't then your parameters are not OPTIONAL they are REQUIRED.
0 Kudos
JMcNeil
Deactivated User
j.russ

One other quick note/suggestion.  As I mentioned and as you tired when you build a model you can set an parameter to have a default value(incase the enduser decides to go the optional route and not enter a value) so couldn't you just catch this in you python script or your C#/Silverlight code? 
A simple if statement in your code behind; and as you mentioned if you didn't want to
require each developer to republish their code to include a parameter their app probably doesn't care about.
could you catch it in the Python script?  Something simple like:

if User_Name == "":
User_Name = "Default Value"

sorry not too sharp with python at the moment.
0 Kudos