Sunday, April 15, 2012

CRM 2011 Postcode Lookup Solution Version 2.0

This is an extension of a blog I wrote back in June 2011. Here is the link to that blog. There were a few cons to that solution. One of the biggest cons was that the solution was hard coded to fill, only the built-in adress1_city, address1_stateorprovince, address1_country fields. I have updated the code to fill the city/suburb, state and country values to any field including custom fields. These fields have to be text fields.
The updated solution will work with the existing built-in entities as well as the custom entities.Here is the link to download the solution.
The solution consists of 4 files:
  • new_Json2.js (Javascript webresource)
  • new_PostCodeScript(Javascript webresource)
  • new_postcode(custom entity to store postcode information)
  • new_SuburbOptions (HTML webresource)

How does it work:

  • User enters the postcode on postal code field and on onchange event of the field. The solution will retrieve postcode records related to entered postcode.
  • If there is only one record related to entered postcode, the solution will populate the state, suburb and country fields for you.
  • If there are more than one records related to entered postcode, the solution will prompt you to select the appropriate entry.
In the following screen shot, I entered 2000 in postal code field and system prompt to pick the relevant city/suburb.

Installation Directions:

  1. Install the postcode solution.
  2. Open the CRM entity form in customization mode.
  3. Double click on attribute that represents the postalcode attribute.
  4. Add new_Json2.js and new_PostCodeScript to form libraries.
  5. Call loadPostCodeRequest function from new_PostCodeScript. Check the  “Pass execution context as first parameter” and pass the 3 attributes that represent the city, state and country attributes in “Comma separated list of parameters that will be passed to the function” as shown in the following screen shot.event
  6. Save the changes and publish the entity.
  7. Test the solution.


  1. Hello Singh,

    thanks for your solution. It helps me a lot, but I have one question. Is there a way to fill lookup-fields (my country field) and fields with an optionset (my stateorprovince-field) with your solution?

    Kind regards from Germany

    1. Found the solution for the optionset. I tried to set the name instead of the value. With the value it works and it is no problem to replace the state/province in my import file with the values of the optionset. But with the lookup-field I have to do more investigation, maybe there is now way to do it?! Really important for me was to fill city and state/province, which works now. Thanks again for your solution.

      Kind regards from Germany

    2. Hi Andreas,

      The solution is built around text fields. To make it work with lookup field, you need to retrieve the guid of the country before assigning to the value. I may think about changing it in next addition.


  2. Hello Singh

    I have installed your solution V2 - works fine on Address1 but when I try to add to More Addresses form where there is no Address1 fields.
    I changes the paremters as follows 'address_city','address_stateorprovince','address_country'

    Can you help me out?
    Tony - Canberra

  3. Hello Singh,

    thank you for your solution. I've followed your guide but nothing happens when I type a post code.

    Do you have any suggestion?

    Kind regrads,

    Thanh-Hai, Germany

  4. Can the solution be extened to pull in the latitued and longitued from the supplied PostalCode database ?

  5. Yes you can. Change the Post Code entity. I have a look and update the solution.

  6. Just a little addition for UR12 and cross browser support. In case of more than one record related to the entered postcode the prompt don't works in Firefox. The prompt is shown, but I only see the checkboxes - no text for the different cities. In Chrome and IE it works perfectly with UR12, in Firefox is only this little limitation. Maybe you can change this if there will be a 3.0 version :-)

  7. I love this blog because it is user friendly with appreciative information. postcodefinder