Changing the data type of a field in Microsoft Dynamics 365 CRM is a common requirement, especially when you need to ensure data consistency and enforce specific data entry rules. However, directly changing a field’s data type from a string to an option set (picklist) is not possible in Dynamics 365 CRM. Instead, the process involves creating a new field with the desired data type and then migrating the existing data to this new field.
In this article, we will walk through the steps to achieve this change, including creating an option set, migrating data, and removing the old field.
Steps to Change Field Data Type
Step 1: Backup Your Data
Before making any changes, it’s essential to back up your data to ensure that you have a restore point in case something goes wrong.
- Export the Data:
- Go to the Advanced Find feature in Dynamics 365 CRM.
- Create a view that includes the entity and the field(s) you are about to change.
- Export the data to Excel to have a copy of all the records as a backup.
- Backup the Solution:
- Navigate to Settings > Solutions.
- Select the solution that includes the entity and fields you want to modify.
- Click Export Solution and choose to export as either managed or unmanaged, depending on your preference.
Step 2: Identify the Field to Be Changed
- Navigate to the Solution:
- Open the Dynamics 365 CRM environment.
- Go to Settings > Solutions and select the solution where the field resides.
- Find the Entity:
- Open the entity (e.g., Account, Contact) where the field you want to change is located.
- Go to Fields and locate the field you want to change from a string to an option set.
Step 3: Create a New Option Set Field
- Create a New Field:
- Click on New Field to create a new field.
- Set the Display Name and Name for the new field.
- Choose Data Type as Option Set.
- Define the Option Set values that will replace the existing string values.
- Add Options to the Option Set:
- If this is a new global option set, choose Yes under the Use Existing Option Set and select from the list or create a new global option set.
- Otherwise, add individual options with their labels and values.
- Save and close the field creation window.
Step 4: Migrate Data from the Old String Field to the New Option Set Field
- Create a Data Migration Process:
- Use Power Automate or a Bulk Data Import tool to map the existing string values to the new option set values.
- For example, create a flow in Power Automate that triggers a record update, checks the string value, and sets the corresponding option set value.
If `StringField` = "Option1" then set `NewOptionSetField` = "Option1"
If `StringField` = "Option2" then set `NewOptionSetField` = "Option2"
- Run the Migration Process:
- Test the migration with a few records to ensure data is mapped correctly.
- Run the process to update all relevant records.
Step 5: Update Forms and Views
- Update Forms:
- Open the forms where the old field is displayed.
- Replace the old string field with the new option set field.
- Save and publish the form changes.
- Update Views and Reports:
- Ensure that the new field is included in all relevant views and reports.
- Remove any references to the old field.
Step 6: Remove the Old String Field
- Delete the Old Field:
- Go back to the Fields area of the entity.
- Select the old string field and click Delete. Ensure that all dependencies (such as scripts, workflows, etc.) are updated or removed before deleting the field.
- Publish the Changes:
- Click Publish All Customizations to apply your changes to the system.
Example Scenario
Consider a scenario where you have a custom field called “Customer Type” of data type Single Line of Text
(string) on the Account
entity. You want to change this field to a Option Set
with predefined values like “Individual”, “Corporate”, and “Government”.
- Create a New Option Set Field:
- Name:
New Customer Type
- Option Set Values:
- 1 = Individual
- 2 = Corporate
- 3 = Government
- Name:
- Use Power Automate to Migrate Data:
- Create a flow that reads the value from the existing “Customer Type” field and sets the corresponding value in “New Customer Type”.
If 'Customer Type' = "Individual" then 'New Customer Type' = "Individual"
If 'Customer Type' = "Corporate" then 'New Customer Type' = "Corporate"
If 'Customer Type' = "Government" then 'New Customer Type' = "Government"
- Update All Forms and Views:
- Replace the old “Customer Type” field with “New Customer Type”.
- Replace the old “Customer Type” field with “New Customer Type”.
- Remove the Old Field:
- Delete “Customer Type” after ensuring no references exist.
In Dynamics 365 CRM, changing a field’s data type requires careful planning and execution. Make sure you take a backup before making any changes. Following these steps will allow you to convert a string field into an option set, ensuring your data is consistent and your users have a better experience.