Answered by:
CRM Console App setting Owner of new record

Question
-
How do I set the owner of a record that I'm creating in a console app? Do I use CrmEntityReference?
:
Guid OWNERID = (Guid)myReader["owner"]; //GUID returned from SQL SP dataset
var CONTACT = new Contact()
{
//set Contact fields here
};
CONTACT.OwnerId = new Microsoft.Xrm.Client.CrmEntityReference("SystemUser", OWNERID);
xrm.AddObject(CONTACT);David Withers
Wednesday, July 25, 2012 6:55 PM
Answers
-
Found the answer (not from copying MS SDK websites)
Guid OWNERID = (Guid)myReader["owner"];
OwnerId = new Microsoft.Xrm.Client.CrmEntityReference(SystemUser.EntityLogicalName,OWNERID)
David Withers
- Marked as answer by David Withers Thursday, July 26, 2012 3:53 PM
Thursday, July 26, 2012 3:53 PM
All replies
-
You need to use the AssignRequest, see MSDN http://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.assignrequest.aspx with something like this...
// Create the Request Object and Set the Request Object's Properties
AssignRequest assign = new AssignRequest
{
Assignee = new EntityReference(SystemUser.EntityLogicalName, _otherUserId),
Target = new EntityReference(Account.EntityLogicalName, _accountId)
};
// Execute the Request
_service.Execute(assign);// where _service is the OrganizationServiceProxy
You can get examples for these in the SDK documentation @ http://www.microsoft.com/en-us/download/details.aspx?id=24004
Thanks,
RBaliga
Wednesday, July 25, 2012 7:42 PM -
so when you are creating a record you cannot set the owner?
David Withers
Thursday, July 26, 2012 4:37 AM -
Found the answer (not from copying MS SDK websites)
Guid OWNERID = (Guid)myReader["owner"];
OwnerId = new Microsoft.Xrm.Client.CrmEntityReference(SystemUser.EntityLogicalName,OWNERID)
David Withers
- Marked as answer by David Withers Thursday, July 26, 2012 3:53 PM
Thursday, July 26, 2012 3:53 PM