Copying Attributes from one Entity to Another
NOTE: THIS IS AN UNSUPPORTED MEANS OF CUSTOMIZING THE ENTITY. I WILL INVESTIGATE A SUPPORTED SCENARIO AND MODIFY THIS POST.
I have been asked many times, “If I customize this entity can I simply copy the attributes to another entity or do I need to create them from scratch?”. The answer has been “No, there is no feature in CRM to do this. You need to create them again”. So I decided to dig in a bit and figure this out. I came across the following post from CRM MVP Matt Wittemann which discusses copying the attribute portion of the entity. There’s the answer. While a pretty easy solution, it is not as easy as you would expect, unless you know the trick. :) So in this post I will show how to copy all the address attributes from the Account entity to a custom entity.
- Export the Account entity customizations.
- Use an xml viewer (I use Visual Studio 2008) to find the entity attributes. Ctrl+f using <attributes> usually does the trick or simply collapse the elements under Account.
- Copy the the address attributes (I excluded the AddressId primary key values for both Address1 and Address2 as that didn’t seem logical to copy to a new entity – don’t want to break anything here!). If you are lazy (and I am sure many of you are) I have posted the address attributes here.
- Paste the address attributes into the desired entity. Make sure insert them within the <attributes> section!
- Here comes the trick(s). In this example we are copying system attributes (not custom attributes) so you will need to update each attribute to replace <IsLogical>1</IsLogical> with <IsCustomField>1</IsCustomField>.
- If it is not a system attribute the <IsLogical>1</IsLogical> value may not exist. In that case simply add <IsCustomField>1</IsCustomField> after <ValidForReadApi>1</ValidForReadApi>.
- If the custom attribute is a picklist, each picklist has 2 attributes (<Type>picklist</Type> and <Type>virtual</Type>).
- Update the <Type>picklist</Type> attribute to either replace <IsLogical>1</IsLogical> with <IsCustomField>1</IsCustomField> or simply add <IsCustomField>1</IsCustomField> after <ValidForReadApi>1</ValidForReadApi>.
- Update the <Type>virtual</Type> attribute by adding <IsCustomField>1</IsCustomField> after <ValidForReadApi>1</ValidForReadApi> retaining <IsLogical>1</IsLogical>.
- Import the modified entity customizations into CRM.
- You will now have all the address attributes listed within the entity attributes that you can add to the form.
I have created a custom Partner entity (as seen above) following this process and posted the Partner entity.xml here as an example. Note: The entity .xml contains the form (including OnLoad, OnSave and OnChange events), views, attributes, and relationships. In this Partner example I have included the OnLoad and Country OnChange events to make the hierarchical picklist work. For more details on hierarchical State / Country picklists check out this post.
-Eric Boocock
Comments
- Anonymous
June 05, 2009
The comment has been removed - Anonymous
June 05, 2009
I have been asked many times, “If I customize this entity can I simply copy the attributes to another