Change global optionset mapping for a Entity optionset in Microsoft Dynamics CRM without dropping and recreating the field

Recently I came across a situation where my local optionset was pointing to one global optionset and then I needed to point to another global optionset. In CRM to do this, you would have to drop the field and recreate field. But the problem is if you have a running system which is being actively used, you may not be at the luxury of dropping and recreating the fields. Let’s see how we can overcome this situation.

Before continuing, please note that the below procedures is not recommended by Microsoft and interacting directly with CRM Organization database might cause CRM to work incorrectly and following the recommended way is what you should look for.  I would strongly recommend taking a back-up of your customizations and organization database.

 

I have field “Test Local optionset”  for the contact entity which points to the global optionset “Global Optionset 1”.  Check for the screenshot below. Screen5

But say we need it to map to another Global optionset called “Global Optionset 2”. To do the same, open the CRM Organization database and run the below SQL query on the database.

DECLARE @OptionsetId UniqueIdentifier

SET @OptionsetId = (Select OptionSetId from OptionSet where Name = ‘new_globaloptionset2’)

Update Attribute SET OptionSetId = @OptionsetId WHERE LogicalName = ‘new_testlocaloptionset’ and EntityId = (SELECT top 1 EntityId From Entity where LogicalName = ‘contact’)

After this query is executed, when CRM is re-opened we could see that our Local Optionset set is now pointing to the “Global optionset 2” instead of “Global Optionset 1”

screen6

 

Now there is a question as to what should be with the existing data for the field.  For that a simple console batch to update the previous values with the new values using text matching condition would resolve the problem. This can be easily achieved with CRM SDK Code. Hope this helps! Happy coding.

Advertisements

About Debajit
I am a Dynamics CRM Most Valuable Professional (MVP) with 10 years of experience in Microsoft .NET Technologies and 7 years of dedicated experience in Microsoft Dynamics CRM. I have worked with companies like Microsoft, SanDisk, PwC, TMF Group and have extensive experience of implementing complex CRM solutions from both offshore and client side. Currently the face of XrmForYou.com with significant experience in delivering corporate training on Dynamics CRM and have already delivered multiple projects to client through XrmForYou.com Author of multiple tools on codeplex including the 'Role Based Views' and 'CRM-Sharepoint Metadata manager & Attachment Extractor' which are available for commercial use under XrmForYou.com For consulting/ training, drop me a note at info@xrmforyou.com or visit our website www.xrmforyou.com

One Response to Change global optionset mapping for a Entity optionset in Microsoft Dynamics CRM without dropping and recreating the field

  1. Pingback: Change Field data type in MSCRM without dropping and recreating the field | Debajit's Dynamic CRM Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: