Changing the Options in a Dynamics CRM OptionSet (Picklist) programmatically, using the SDK

I recently needed to make a deployment routine remove unwanted options from out-of-the-box Option Sets (Picklists) like Campaign > Campaign Type and Contact > Preferred Contact Method. I needed to do this because even if you remove them on a Dev environment, they are not deleted when a solution is imported into a Test or Production environment.

Usually, the UpdateAttributeRequest is used to change an attribute’s metadata. However, if this is used with a PicklistAttributeMetadata (which represents an Option Set) that includes modifications to its OptionSet.Options collection, these will be ignored, even though other changes to the metadata will be applied, and no error will occur.

Global Option Sets can be updated with an UpdateOptionSetRequest, but this causes an error when used with a local Option Set.

The answer is the DeleteOptionValueRequest which will remove a single option from an Option Set (Picklist).

It’s used like this:
new DeleteOptionValueRequest {
AttributeLogicalName = "yourattribute",
EntityLogicalName = "yourentity",
Value = 2});

If this is useful, you might also want to know about these other related Requests:

Leave a Reply

Your email address will not be published. Required fields are marked *