tags:

views:

758

answers:

2

Using the Dynamics CRM I'm trying to create an instance of an entity. I would like to manually set the GUID, but if I had the attribute that is the primary key to the DynamicEntity, I get "Service could not process request" back.

I am building a DynamicEntity, and setting the [entityname]id attribute causes the request to fail. It's moving data between two CRM instances, so if anyone knows of a better way to copy records between CRMs, that'd work too. Otherwise, I'd like the GUID to match across instances... as that's the point of a GUID.

+2  A: 

Happily, it IS possible to do this across two CRM instances! A co-worker knew the solution, so credit really belongs to him.

My mistake was creating a Property with type UniqueIdentifierProperty. The primary key attribute on an entity needs to be filled in with a KeyProperty. These two properties are nearly identical -- the Property types are, except that one holds a Key, the other a UniqueIdentifier. The Key/UniqueIdentifier both hold GUIDs. (Another day in the mind of Microsoft!)

Precisely, what I'm doing is creating a DynamicEntity, filling in the entity name, and filling in the majority of the attributes. The PK attribute (which you can determine from the metadata) can be filled in with a KeyProperty. I was filling it in with a UniqueIdentifierProperty, which CRM rejects and responds with a nondescript and unhelpful error message.

Thanatos
*sigh* The plot thickens. While the above works, CRM still gets in the way. If you delete a record in CRM, it is not really gone, it is merely "marked" for deletion -- see the DeletionStateCode. These are deleted every (insert arbitrary number here) hours. During that time however, the GUID is still in the database, so you can not insert another record (duplicate PK). You can kludge around the problem by dropping the whole entity, and recreating it. Why in God's name Microsoft decided this was a bright idea is beyond me. It's going to be deleted. Just DROP the record...
Thanatos
A: 

I apologize if I am over-simplifying the solution, but why not add a custom field in both instances that would be a mirror of the other instances guid?