Dynamics CRM does not support dropdowns for the lookup fields out of the box, but it is not unusual when we really need a dropdown rather than a lookup. The most obvious example is when we need to set country/state for the address field in the contact record. Whatever the reason is, in the default Dynamics configuration we can only type in country/state names.
So, this post describes a javascript solution that allows for a few things:
- Create a drop down where we would normally have to use a lookup
- Propagate selected reference and/or text to the pre-existing entity field
- Implement parent-child relationships between two or more dropdowns
This solution does use a bit of HTML manipulation to replace image web resource with a drop down, but, other than that, it relies on OData services and Xrm.Page client-side API.
You will need to download a couple of Dynamics solutions:
http://gotchahunter.net/downloads/GotchaHunter_1_0.zip
http://gotchahunter.net/downloads/GotchaHunterTests_1_0.zip
Please note that both solutions are unmanaged. The first one contains web resources only, so it is safe to deploy it.
The second one is for testing only since it has some customizations, yet it adds some other entities (such as country and province). In other words, use it as a reference and feel free to play with it in the test environment. Make sure you know what is there before you install it into a more “permanent” environment.
For the purpose of this blog post, you can use the second solution only (since it also contains all the scripts).
So, follow these steps to try the solution:
- Get a clean instance of Dynamic (CRM online would do
)
- Deploy GotchaHunterTests_1_0.zip and publich customizations
- Make sure tcs_country and tcs_province entities are visible in the workplace (if not, update those two entities)
- Create a couple of countries
- Create a few provinces for at least one of those countries
- Now, go to one of the contacts
- Notice that you have two dropdowns. When you change selected item for any of those dropdowns, original text fields will be updates, too:
- Technically, you don’t need to display those original text fields on the form, so you could update the form to “not display” those fields by default(just do not remove them from the form)
And that’s, pretty much, it. In the next post, I’m going to explain how to make these dropdowns work from scratch, without using my “Tests” solution (that’s where you will need the first link above – that solution contains all the required scripts and no other customizations).
