Philip's profilePhilip RichardsonBlogLists Tools Help

Blog


    April 03

    Programmatically Modifying Picklists

    I have been infected with the Program Management cold (again). I suspect our competitors are placing germs in our building's air conditioner. The following post is taken from a reply I sent on an internal CRM mailing list - regarding the method to programmatically modify picklists. I thought it might be useful to a broader audience. Please excuse it's sketchy nature. Remember - blogs are inspirational not instructional.
     

    Here is the methodology for getting to the account picklists (but it works with pretty much any entity).

     

    ExportXmlRequest exportRequest = new ExportXmlRequest();

    exportRequest.ParameterXml = @"<importexportxml>

                                              <entities>

                                                    <entity>account</entity>

                                              </entities>

                                              <nodes/>

                                  </importexportxml>";

     

    ExportXmlResponse entities = (ExportXmlResponse)service.Execute(exportRequest);

     

     

    Now you will have string containing the Account ImportExport.xml. Load this into a XML document.

     

    Now parse throught the Attributes element looking for picklist attributes:

                <attribute PhysicalName="PreferredContactMethodCode">

                  <Type>picklist</Type>

                  <ValidForCreateApi>1</ValidForCreateApi>

                  <ValidForUpdateApi>1</ValidForUpdateApi>

                  <ValidForReadApi>1</ValidForReadApi>

                  <DisplayMask>ValidForAdvancedFind|ValidForForm|ValidForGrid</DisplayMask>

                  <Description>Preferred contact method for the account.</Description>

                </attribute>

     

    The actual picklist values are in the FieldXml element (not in the attributes - this is the trap for young players).

                <field name="preferredcontactmethodcode" requiredlevel="na" defaultvalue="1">

                  <displaynames>

                    <displayname description="Preferred Method of Contact" languagecode="1033" />

                  </displaynames>

                  <options nextvalue="7">

                    <option value="1">

                      <labels>

                        <label description="Any" languagecode="1033" />

                      </labels>

                    </option>

                    <option value="2">

                      <labels>

                        <label description="E-mail" languagecode="1033" />

                      </labels>

                    </option>

                    <option value="3">

                      <labels>

                        <label description="Phone" languagecode="1033" />

                      </labels>

                    </option>

                    <option value="4">

                      <labels>

                        <label description="Fax" languagecode="1033" />

                      </labels>

                    </option>

                    <option value="5">

                      <labels>

                        <label description="Mail" languagecode="1033" />

                      </labels>

                    </option>

                  </options>

                </field>

     

    Now you can edit these values here and then re-import the data back to CRM the ImportXml and Publish web service messages.

     

    Hint: don’t get distracted by the languagecode …. these are not the droids you are looking for.

     
     
    This posting is provided "AS IS" with no warranties, and confers no rights.

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.
    Philip Richardson has turned off comments on this page.

    Trackbacks

    The trackback URL for this entry is:
    http://philiprichardson.spaces.live.com/blog/cns!E1C114B0FC9B3FE!632.trak
    Weblogs that reference this entry
    • None