| Philip's profilePhilip RichardsonBlogLists | Help |
|
April 03 Programmatically Modifying PicklistsI 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.
TrackbacksThe trackback URL for this entry is: http://philiprichardson.spaces.live.com/blog/cns!E1C114B0FC9B3FE!632.trak Weblogs that reference this entry
|
|
|