Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I've got a website that I want to extend by letting people look up postal/zip codes for an address they enter. I've already got all the addresses (with their postal codes) for the city in an ArcSDE geodatabase.

What I'd like to happen is that the user will enter a civic number, select a street from a dropdown list and then upon clicking a button the postal code for the address will appear in it's text box.

I've created a script tool that takes two arguments: civicNumber and streetName and then uses a search cursor to get the postal code for the address. If it finds the postal code the tool uses arcpy.AddMessage() to return the postal code.

This actually works, I've turned the tool into a GP Service and tested it from the web and the postal code is indeed being returned in a esriJobMessageTypeInformative JSON object.

My question is this: Is there any way for the Python script to return the Postal Code as a string without using the arcpy.AddMessage() function?

share|improve this question
up vote 7 down vote accepted

You could return it as a parameter.

outputAddress = #logic you already have to get this    
arcpy.SetParameterAsText(2, outputAddress) 
#2 being the index, since you have 2 inputs (0, 1), I say 2 being your 3rd parameter

After this bit of code, its just a matter of creating a new output parameter in the script tool properties. I'd make it a derived string. Your web app would then get the output result (of type string) and display it some way.

share|improve this answer
Thank you very much! I knew there must be a cleaner way :D – Samuel Henderson Apr 10 '13 at 14:32
It is worthy to note that all parameters have one shared index - so if you have one input parameter arcpy.GetParameterAsText(0) - then you need arcpy.SetParameterAsText(1..) /I thought it would be 0, but no - they share index. – Alex Tereshenkov Nov 14 '13 at 13:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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