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.

1 thought on “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

Comments are closed.