18 Feb
Posted by: mitch in: Customization, Dynamics CRM, Unsupported
When you create a new Entity within MSCRM you have a choice to make regarding the ownership of that Entity.
From the MSCRM 3.0 Help File:
In the Ownership list, select either:
- User
Records for this entity can be owned by individual users. For example contact records are set to User.– OR –- Organization
Records for this entity are used for reference by all Microsoft CRM users, and so are not owned by individual users. For example, product records are set to Organization.
While attending an MSCRM Troubleshooting class last week, I learned something that isn't readily apparant when you are creating enties:
In order for a custom entity to be available to the CRM Workflow module, it must be created with an ownership of User.
This was news to me, and unfortunately, unwelcome news. I had just created 12 custom Entities that had a combined total of over 100 Attributes and Relationships out the wazzoo. Since you can't change the Ownership type after creation, I was looking at spending a few hours deleting my existing Entities and recreating them from scratch.
And after thinking about it, I understand why the ownership requirement for workflow exists, I just wish it had been better documented.
Anyway, I was thinking ( mustly hoping ) that there just had to be a way to alter the definition of the Entity without having to manually recreate it. It turns out, there is, but it is a bit of work.
The following information is provided as-is, without any warranty, either expressed or implied.
It is probably unsupported by Microsoft as well.
Use this information for reference and as a last-resort.
How Entities are Organized
With the exception of three Attributes, the tables of a User Owned Entity and an Organizational Owned Entity are exactly alike. The following table contains the Attributes created when you create both types of Entities. Those in bold are specific to that Ownership type.
| Organization Ownership | User Ownership | ||
| Name | Type | Name | Type |
| createdby | lookup | createdby | lookup |
| createdon | datetime | createdon | datetime |
| createdon | datetime | createdon | datetime |
| modifiedby | lookup | modifiedby | lookup |
| modifiedon | datetime | modifiedon | datetime |
| new_2blankoid | primarykey | new_2blankoid | primarykey |
| new_name | nvarchar | new_name | nvarchar |
| statecode | state | statecode | state |
| statuscode | status | statuscode | status |
| organizationid | lookup | ownerid | owner |
| owningbusinessunit | lookup | ||
So, how do we convert an Entity from one ownership type to another as cleanly as possible and keeping the destruction to a minimum? I've successfully performed the following steps and have seen no side effects.
Step 1: Back up your CRM databases.
Step 2: Export All Customizations.
Even though you may only be working with one or two Entities, I feel it is best that all Entities be included in the export to ensure that we don't miss anything.
Step 3: Make a backup copy of your exported customizations.
Just in case your edits do not work as planned.
Step 4: Delete the custom entity that needs to be reassigned Ownership.
Sorry, there is just no way around this step. The Import Customizations process only adds data and changes, it will not delete anything, and we must delete attributes. That means data loss.
Step 5: Open the exported customizations in WordPad.
Or whatever your favorite XML editor is. Just remember how picky CRM 3.0 is about its XML format. Personally, I use WordPad because it doesn't introduce additional line feed characters that so offend CRM.
Note: Steps 6 - 8 will be repeated for each Entity that needs to be altered.
Note 2: DO NOT attempt to copy the following XML from this blog and insert it into your CRM Export file. It will break the file and you will be unable to import it. I would suggest Exporting a single Entity with User Ownership and have that open in a separate WordPad instance to copy the code from.
Step 6: Change the ownership type.
Find the following code:
<OwnershipTypeMask>OrgOwned</OwnershipTypeMask>
And replace it with the following:
<OwnershipTypeMask>UserOwned</OwnershipTypeMask>
Step 7: Remove the Organization Attributes and Insert the User Attributes
DELETE THE FOLLOWING CODE
<attribute PhysicalName="OrganizationId">
<Type>lookup</Type>
<ValidForReadApi>1</ValidForReadApi>
<ReferencedEntityObjectTypeCode>1019
</ReferencedEntityObjectTypeCode>
<Description>Unique identifier for the organization</Description>
</attribute>
INSERT THE FOLLOWING CODE
<attribute PhysicalName="OwnerId">
<Type>owner</Type>
<IsNullable>0</IsNullable>
<ValidForCreateApi>1</ValidForCreateApi>
<ValidForUpdateApi>1</ValidForUpdateApi>
<ValidForReadApi>1</ValidForReadApi>
<IsLogical>1</IsLogical>
<DisplayMask>ValidForAdvancedFind|ValidForForm|ValidForGrid
</DisplayMask>
<Description>Owner Id</Description>
</attribute>
<attribute PhysicalName="OwnerIdDsc">
<Type>int</Type>
<IsNullable>0</IsNullable>
<ValidForReadApi>1</ValidForReadApi>
<IsLogical>1</IsLogical>
<AttributeOf>OwnerId</AttributeOf>
<XmlAbbreviation>dsc</XmlAbbreviation>
<Description />
</attribute>
<attribute PhysicalName="OwnerIdName">
<Type>nvarchar</Type>
<Length>320</Length>
<IsNullable>0</IsNullable>
<ValidForReadApi>1</ValidForReadApi>
<IsLogical>1</IsLogical>
<AttributeOf>OwnerId</AttributeOf>
<XmlAbbreviation>name</XmlAbbreviation>
<IsSortAttribute>1</IsSortAttribute>
<Description>Name of the owner</Description>
</attribute>
<attribute PhysicalName="OwnerIdType">
<Type>int</Type>
<ValidForCreateApi>1</ValidForCreateApi>
<ValidForReadApi>1</ValidForReadApi>
<IsLogical>1</IsLogical>
<DisplayMask>ObjectTypeCode</DisplayMask>
<AttributeOf>OwnerId</AttributeOf>
<XmlAbbreviation>type</XmlAbbreviation>
<Description>Owner Id Type</Description>
</attribute>
<attribute PhysicalName="OwningBusinessUnit">
<Type>lookup</Type>
<ValidForReadApi>1</ValidForReadApi>
<ReferencedEntityObjectTypeCode>10
</ReferencedEntityObjectTypeCode>
<Description>Unique identifier for the business unit that owns the record</Description>
</attribute>
<attribute PhysicalName="OwningUser">
<Type>lookup</Type>
<ValidForCreateApi>1</ValidForCreateApi>
<ValidForUpdateApi>1</ValidForUpdateApi>
<ValidForReadApi>1</ValidForReadApi>
<ReferencedEntityObjectTypeCode>8
</ReferencedEntityObjectTypeCode>
<AggregateOf>OwnerId</AggregateOf>
<Description>Unique identifier for the user that owns the record.</Description>
</attribute>
Step 8: Change the form fields from Organization to User.
DELETE THE FOLLOWING
<field name="organizationid" requiredlevel="na">
<displaynames>
<displayname description="Organization Id" languagecode="1033" />
</displaynames>
</field>
INSERT THE FOLLOWING
<field name="ownerid" requiredlevel="na">
<displaynames>
<displayname description="Owner" languagecode="1033" />
</displaynames>
</field>
<field name="owningbusinessunit" requiredlevel="na">
<displaynames>
<displayname description="Owning Business Unit" languagecode="1033" />
</displaynames>
</field>
Step 9: Save and close the Export file
Step 10: Import the modified Exported customizations
Step 11: Publish All Customizations
Do this before you do anything else with the system as it will ensure that all of the data is completely replication throughout the CRM 3.0 system.
Finished.
Just to make sure everything is fine within the CRM 3.0 system, I perform the additional steps:
Step 12: Add a temporary Attribute to the altered Entity.
This is really just to make sure that the CRM Entity modification process still functions as expected.
Step 13: Add that Attribute to the data entry Form.
Step 14: Publish the Entity
Step 15: Create and save a new record for the altered Entity.
Step 16: Delete the temporary Attribute from the Entity.
Step 17: Publish the Entity.
Really Finished.
Good luck and if you find any issues, please let me know.
2 Responses
Shai
19|Feb|2006 1Hi Mitch !
This article and all the other too are great.
Keep bring them.
TIA
Shai
jaber
03|Feb|2008 2Hi Mitch
Nice Example.
I have created a LookUp Attribute. when I save the record and open it again the name in the Look up field disappeared and left it with only the image. I tried a lot but cannot able to find a solution. If you can able to help me out I am really thankful to you.
Leave a reply