Have you ever created a pick-list with a significant number of entries, and gotten pretty sick of adding items one at a time in the MSCRM GUI? I faced this recently when I had a customer ask me how to easily create a pick-list with all the countries in the world in it.

So facing the prospect of clicking the "Add" button on a pick-list 194 times (at least I *think* that's how many countries exist in the world today! :)) I decided to write a little utility to generate the pick-list code for me. After all, when you add a custom pick-list to an object form, and add some items to it, you can then export the XML for that object and see the list of items. What the utility does is read in a list of item values, and generates the XML tags which you can then paste into your customizations file to be imported. Note that this utility assumes you have your list of entries in a soft file somewhere!

The first thing you need to do is grab the utility executable file, the archive also has a list of countries if you want to test this.

Download this version if you have v1.1 of the .NET Framework:

PickListXml for .NET v1.1

Download this version if you have v2 of the .NET Framework:

PickListXml for .NET v2

 

Step 1, add a new custom pick-list to your CRM object, for this example we will add a "Country" pick-list to the Account Object. In MSCRM, click Settings->Customization->Customize Entities and double click the "Account" object

Once you open the Account object, click the "Attributes" navigation item, and then click the "New" button.

Set your new attribute to a pick-list, and then name it something like "Country". Click the Add button a few times and add a few temporary values, later these values will show us where to paste our generated XML.

After adding some values you should see something like shown below. Click "Save and Close", and then "Save and Close" again.

When you get back to the Customizations screen, make sure the Account row is selected as shown, and then click "Publish"

When that finishes, add the pick-list to the account form, which I am going to assume you know how to do! After following these steps, if you open the account form you should see something similar to the image below, note the "Country" pick-list with values.

Next Click the "Customization" link again, and then click "Export Customizations". Again make sure the Account row is selected as shown, and then click "More Actions->Export Selected Customizations"

When prompted, click "Save" and then give your file a meaningful name, like "account_customizations.xml"

Now, open the file you just saved in your favorite editor, and search for the custom attribute you just added, remember that the new attribute will be named <your customization prefix>_picklistname. So for example, my customizations prefix is "Johnz" so I searched for "Johnz_Country", and found the XML for the pick-list. Note that you have to search for the string several times to find the section where the options are set, the XML will look something like shown here.

<field name="johnz_country" requiredlevel="na" defaultvalue="">
<displaynames>
<displayname description="Country" languagecode="1033" />
</displaynames>
<options nextvalue="4">
<option value="1">
<labels>
<label description="Test" languagecode="1033" />
</labels>
</option>
<option value="2">
<labels>
<label description="Test 2" languagecode="1033" />
</labels>
</option>
<option value="3">
<labels>
<label description="Test 3" languagecode="1033" />
</labels>
</option>
</options>
</field>

Next we are going to run the utility you downloaded at the beginning of this article, however note the utility expects a text file of value names, one per line. So for example if you open the included "countries.txt" file you'll see one country name per line like this:

Afghanistan
Albania
Algeria
Andorra
Angola
Antigua and Barbuda
Argentina
Armenia
Australia
Austria
Azerbaijan

So when you run the utility you'll see:

If you click the "Choose File" button you'll see a standard file chooser dialog:

Please note that as soon as you double-click on the file, or choose a file and click "Open" the utility will run and generate the XML. So be sure you chose the right file. Also note that the output will be a file called "list_with_xml.xml" and it will be in the same directory you run the utility from. So if you unzip the archive to C:\temp and run the utility, the output file will be in C:\temp.

That's what I did in this example, I ran the utility from C:\temp, choose the "countries.txt" file as input, and the result is shown below:

My status label changes to "Done!"

and I can see my output file in C:\Temp:

Now if you open that file, you'll see that the XML for the pick-list options ahs been generated, and we can copy and paste that XML over the temporary option values we created using the MSCRM GUI. A sample from the output file is shown below.

<option value="1">
<labels>
<label description="Afghanistan" languagecode="1033" />
</labels>
</option>
<option value="2">
<labels>
<label description="Albania" languagecode="1033" />
</labels>
</option>
<option value="3">
<labels>
<label description="Algeria" languagecode="1033" />
</labels>
</option>

Please note that the utility assumes you are replacing ALL the options currently in the pick-list with the generated values, that's why the "Option value" numbering starts at 1.

So, now we can just copy and paste the generated XML into our customizations file. Select all of the generated XML in the "list_with_xml.xml" file and choose Edit->Copy from the menu:

 

Then, in the customizations file (mine is called "account_customizations.xml") select the XML for the options in the pick-list, and select Edit-Paste:

 

The result should look similar to this:

Save the file!

Next, in MSCRM  choose Settings->Customization->Import Customizations. Browse to your customizations file and click "Open", then click Upload

Next click More Actions->Import Select Customizations.

When you see the screen below, click "OK.

Next as we did earlier, you must click "Settings->Customization, make sure "Account" is selected, and click "Publish".

That's it! Click Sales->Accounts and then the new button, and check out your new pick-list with all the countries in the world!

 

This utility and method will work for any list you want to make into a pick-list, however the steps involved might be more effort than adding items manually until you get to picklists of 20 or more values.