views:

485

answers:

3

For integration purposes our users in Dynamics CRM need to have the same GUIDs as in the rest of our environment (several custom web apps built on ASP.NET and SQL Server 2005). But when we try to create a new Dynamics user with a certain GUID, Dynamics just ignores it and creates its own (the pattern of which leads me to believe that it’s using NEWSEQUENTIALID() internally, just as if the user was created through the UI). But for other types (contact for example) Dynamics takes the GUID with no issue.

Am I doing something wrong, or does Dynamics always ignore GUIDs on new user creation?

CrmService service = GetService();

systemuser newUser = new systemuser();

Key newUserId = new Key();
newUserId.Value = new Guid("D630FA8D-A32F-4a37-BFEF-CE36CBA29009"); 
  // The GUID I would like Dynamics to use
newUser.systemuserid = newUserId;

Lookup bu = new Lookup();
bu.Value = new Guid("16B10365-0E18-DF11-B839-005056B60DD4"); 
  // The correct business unit ID.  Nothing to see here.
newUser.businessunitid = bu;

newUser.firstname = "John";
newUser.lastname = "Doe";
newUser.domainname = "DOMAIN\\jdoe";
  // Valid AD credentials too.  Names changed to protect the innocent.

Guid userId = service.Create(newUser);
Console.WriteLine("User created with GUID " + userId.ToString());
  // Dynamics creates the user with a completely different GUID. :-(

Edit:

I've now asked this question on Microsoft's CRM forum as well.

+2  A: 

I know it is not ideal, but as a workaround you could add a custom attribute to the systemuser entity and store your integration id there.

Matt Dearing
+1  A: 

Without knowing more about your solution I can tell you that you don't need hardcoded quids everywhere like you are trying to do. When I arrived at my current client they were trying to do the same things and it was a serious PITA.
It took me about a day to replace all the code that was using the hardcoded quids for various entities with a simple lookup procedure that gets the entity by whatever key (user name in your case) you want and then get the entity's id from that. No more trying to do something you should be trying to do in the first place.

Jake
A: 

It took me about a day to replace all the code that was using the hardcoded quids for various entities with a simple lookup procedure that gets the entity by whatever key (user name in your case)

How interesting. You're searchnig John Doe user by 'John','Doe' strings. And what should I do if I got TWO "John Doe" in my company ?

Brian J. Hakim