Duplicate Field Name Error Creating Field Dynamics CRM 2011

Paul Nieuwelaar, 21 August 2012

The other day I was creating a bunch of fields for a custom entity, of which included a Two Options field, and a Single Line of Text field. For whatever reason, the field name of the Single Line of Text field was to be that of the Two Options field, but with ‘name’ on the end.

I created the Two Options field first, with no problems. When I came to create the Single Line of Text field however, I received the following error:

 Duplicate Field Name Error Creating Field Dynamics CRM 2011

After a minute of scratching my head, knowing that I hadn’t already created this field, I checked the existing fields for this entity, to confirm that a field with this name DID NOT already exist. After some further investigation and testing, I discovered that when a Two Options field is created, the filtered view in SQL is automatically altered to include a name column with the same name as the Two Options field, but with ‘name’ on the end. This is hidden to the front end, but when looking in SQL we can see the column, and the data it stores. As you can see below, this contains the label for the selected option (Yes or No for example), but the actual field contains the physical value of 1 or 0.

 Duplicate Field Name Error Creating Field Dynamics CRM 2011

Luckily I had created the Two Options field first, because if I had created the Single Line of Text field first (new_twooptionsfieldname) and then tried to create the Two Options field after (new_twooptionsfield) I would have received the following SQL error, which does not give me any indication of what the error might be.

 Duplicate Field Name Error Creating Field Dynamics CRM 2011

Of course, this is exactly the same problem. CRM is trying to automatically alter the filtered SQL view to include this ‘name’ column, but a field with that name already exists, so it fails.

In either case, we need to rethink the field naming so that Two Options fields don’t clash with any other fields we might create. This can often be easily avoided by adding ‘Is’ or ‘Are’ in front of the Two Options field name, for example ‘Is Billable’.