2

I want to publish a GP Service to ArcGIS Server without default input parameter. However, I also want that GP Service to return an error when no input parameter is provided.

How could I do so? ArcGIS wont let met publish a GP Service that returns an error, and if I run it with a valid input value, it will be defined as the default value and I wont be able to remove it.

2

I have solved this for publishing GP services by doing this:

Publish a service after supplying an empty string as an input parameter.

Source code for a script tool:

import mainmodule
if input_param == "":
    #for GP script tool publishing
    Result = ""
else:
    Result = mainmodule.dowork(input_param)

arcpy.AddMessage("Result: " + Result)

After publishing you will have an empty string as the default value for the parameter. Now you can edit the mainmodule.py and add the logic that will check if the input_param is None and throw any exception.

All my GP services consist of the caller script tool that is used only for publishing (with arcpy params) and another script tool where is the business code. The latter file is not published to server and all updates will be used immediately by the GP service.

  • Thank you for your answer. I was aware of this option, but I dont like the fact that I would have to modify the mainmodule each time I want to republish the GP Service, but if there is no other solution, I'll do it... – Below the Radar Oct 12 '16 at 13:43
  • @BelowtheRadar, no problem. Could you elaborate on what you mean by modify the mainmodule each time I want to republish the GP Service please? When I make changes in the mainmodule.py, I don't need to republish the GP service. I think this is great to separate arcpy GUI and params the business logic into separate modules. – Alex Tereshenkov Oct 12 '16 at 13:54
  • In the script that I publish, there is some constants/ system parameters, used by the main module. In case I need to change them, I would need to republish the GP Service and to do so, I'll need to modify the main module again to prevent the default input value... – Below the Radar Oct 12 '16 at 13:56
  • Well, again, I don't put anything like this into the script tool source code file. All the config values are imported from another module. The script that is being published and copied to the server is only import arcpy, set all input and output params (getparam and setparam), and the call to the functions found in the imported modules. I have used this approach for 3 years and it proved to be an excellent way to avoid republishing anything and it gives great flexibility. – Alex Tereshenkov Oct 12 '16 at 14:00
  • 1
    No problem at all. Check this post out, more details on the workflow I've described - tereshenkov.wordpress.com/2015/04/07/… – Alex Tereshenkov Oct 12 '16 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.