Inserting City and State Automatically based upon Zip Code

I saw an internal question a couple of weeks ago about how do I have CRM auto fill in City and State when I insert the zip code. After noodling on this for a while, there are a couple of different approaches. I would highly recommend you look at the Group1 Data Quality Adapter as it does that and much more. But what if ALL you want is just the City and State with no other bells and whistles. Is this possible? The easy answer is yes.

So to make this happen, I first went on a search of an web services that return data to you in XML that we could parse and insert into CRM. After looking around, the one that seemed to jump out at me is the one from the USPS. After playing with it for a while, I gave up since their licenses is fairly restrictive. (If you are not doing it for USPS shipping and cannot provide them a URL to show them what you are doing, it is a $3500 a year package you need to buy. Or at least that is what they told me.)

In looking at a totally unrelated to CRM blog post, I ran across the Yahoo Maps GeoCoding Web Service. It has a VERY liberal policy of 5,000 hits per day and no username or password are required. In playing with it, it looks like it will do everything you would want around addresses. My only wish is that had this same API I could use. (And yes I went poking around and asked there first.)

So the inspiration for this came from Arash’s post on Multicurrency. After playing with his script for about an hour and realizing that I am really pretty dumb, I emailed Jason and Aaron over at Invoke Systems.

Wouldn’t you know Jason had something handy? Here is his link. He goes a little more in-depth than I want. (VERY Simple for me, insert a zip code and get city and state. Everything else is icing… ) This should be placed on the OnChange for the Zip / Postal Code Field. I have not tried it with any international addresses, yet.

Thanks Jason!

So here is my copy of Invoke’s code with it JUST for City and State

var sUrl = "";

sUrl += "&zip=" + crmForm.address1_postalcode.DataValue;

var oXmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");

oXmlHTTP.Open("GET", sUrl, false);


var oXmlDoc = oXmlHTTP.responseXML;

crmForm.address1_line1.DataValue = oXmlDoc.selectSingleNode("ResultSet/Result/Address").text

    crmForm.address1_city.DataValue = oXmlDoc.selectSingleNode("ResultSet/Result/City").text

    crmForm.address1_stateorprovince.DataValue = oXmlDoc.selectSingleNode("ResultSet/Result/State").text

    crmForm.address1_country.DataValue = oXmlDoc.selectSingleNode("ResultSet/Result/Country").text