Wednesday, July 05, 2006

MSCRM 3: Convert text boxes to picklists using DHTML

All of our MSCRM customers are quite annoyed that the address country field is just a text box and not a drop down list with all existing countries. This makes e.g. reporting by country hard to do. There are several suggested workarounds out there, but Michael Höhne has come up with a very neat tick using DHTML and JavaScript in the OnLoad event of the MSCRM form.

The script replaces the country field with a picklist with the same name/id as the standard text field. This technique can of course be applied to any text field that you would rather see as a picklist.

A nice extension to Michael's script would be to remove the hardcoding of the picklist values with dynamic fetching of the values using a web-service AJAX style. This would make maintenance of the picklist content simpler, providing the super user with a centralized location for picklist management. After all, the country field is used several places in MSCRM; and the lists of countries seems to change every week these days.

Arash Ghanaie-Sichanie's excellent article "Accessing Web Services From CRM Forms" shows how to implement dynamic lookup of values. Note that using a web-service might not be feasible for the MSCRM laptop client (offline).

The full ISO 3166 country list can be found here.