4

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?

1 Answer 1

7

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.

2
  • Thank you very much! I knew there must be a cleaner way :D Commented Apr 10, 2013 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. Commented Nov 14, 2013 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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