Monday, April 9, 2012

CRM 2011: Changing an entity from organization owned to team or user owned without dropping

So after my testing with role based security, it became obvious that the entities that are newly created should be given team or user based ownership to ensure the security would be used correctly.
However what if you already have entities created and are unwilling to drop and recreate the entity?

I have to preface this by saying this is unsupported by Microsoft but will do the trick.
The key is updating not only the customizations xml file but also the EntityView in the SQL database.
To do this you will need the proper role such as System Administrator.

Steps:
1. Gather the necessary xml needed to add owner columns and a team relationship. I find this easier if you can create a sample entity that is user or team owned and copy the specific xml. Always keep a backup of your initial solution to ensure you can roll back.

2. Locate the EntityView inside your database. Navigate to the specific entity in question. Notice the OwnershipTypeMask column. This will be set to 8 and will be updated to 1.

3. Update the EntityView record to OwnershipTypeMask to 1.

4. Once this is done, you can now push your updates to CRM using the solution. The next steps will help you attempt to locate the nodes you need to update.

5. Add the atrributes you gathered from the test entity. These include
OwnerId
OwnerIdName
OwnerIdType
OwnerIdYomiName
OwningBusinessUnit

6. Scroll to the <OwnershipTypeMask> node. If you are using a solution exported from before your sql change, you will have to change the value to say UserOwned.

7. Add to the EntityRelationship section of the file. Again, if you have the test entity do a search for team_ and it should find it. Duplicate this and insert accordingly.

I would only attempt this if you are familiar with modifying the customizations file extensively. One wrong move and you will have to try various routes to revert back.

It can be done but the road is slippery when wet! :)

13 comments:

  1. Hi,

    I have gone through all the steps you highlighted on this post but I am getting this error "Object reference not set to an instance of an object". Can you please advise. Nyiko

    ReplyDelete
  2. I get the same error.

    Is there a table other than MetadataShema.Entity that needs to be updated?

    ReplyDelete
  3. if you are using on premise, then above solution will work. But if you are using on line, then you have to delete the entity first before reimporting the solution

    ReplyDelete
  4. I'm using on premise and get the error too while importing. Is there a trick or something to do this without deleting the entity?

    ReplyDelete
  5. "Entity Owner cannot be a referenced entity because it does not have a lookup saved query" -- I'm trying online and get stuck here. I think I'm SOL.

    ReplyDelete
  6. Review the customizations xml, more specifically, the formXml and view section. There is probably a reference to the organization and/or a reference needed for a user/team.
    I would suggest creating a new user owned entity and reviewing the form and view sections of the customizations.xml. If you notice a lookup for user, copy that node and add to the entity you want to change.
    HTH.

    ReplyDelete
    Replies
    1. good idea, I see the different savedquery for "My Enity's" view.
      Adding that went well, leading to a new error message:
      "The entity relationship role of the referencing entity is required when creating a new one-to-many entity relationship business_unit_new_entityname."

      So I added EntityRelationshipRoles (I found these from another entity... not entirely sure if there is something there I can tweak).

      And that leads to a different error again:
      "Cascade link type 'NoCascade' is invalid for Delete."

      Why is NoCascade invalid? Because it is not a valid option for delete in CUSTOM entities. This is taking me down the road as if this was a custom entity relationship, not a system relationship, which I am trying to trick it to believe.

      All this said, this is an online org! So really it is a pointless endevour, I guess I just had to confirm myself the hard way.

      I will try again in an on-premise environment and make the required sql changes.

      Delete
    2. Just to close the loop, I ended up giving up when I saw this message, after changing the "Cascade link type" to "RemoveLink" and getting this error message:

      "The schema name is invalid or missing. Custom attribute, entity, option set and relationship names must start with a valid customization prefix. The prefix for a solution component should match the prefix that is specified for the publisher of the solution."

      Delete
    3. uh oh. I get the same error in on premise even after the sql applied.

      To second igkum1709's questions,
      In step 5, I deleted the node.
      In step 7, I deleted the EntityRelationship Name='organization_myOrgEntity'> node and copied the team_### node and the owner_### and the user_### node (all 3).

      Delete
  7. This comment has been removed by the author.

    ReplyDelete
  8. I've tried it with a 1:1-copy of the entity, update the OwnershipTypeMask in the SQL database and get the error 'Object reference not set to an instance of an object' on the entity. What are you doing different than me?
    On step 5: Do you delete the <attribute PhysicalName='OrganizationId'> node?
    On step 7: Do you delete the <EntityRelationship Name='organization_myOrgEntity'> node? And copy only the team_### node or the owner_### and user_### node too?

    ReplyDelete
    Replies
    1. great questions, I'd be very interested in the answers if anyone out there is succeeding with this process in CRM 2011 Update 11+.

      Delete
  9. Are you really sure you done this successfully? If you missed out anything, can you please add??? Thanks

    ReplyDelete