How to set OwnerId of any Record in CRM 2011

Basically , unlike CRM4.0, the ‘OwnerId’ cannot be set and then the entity be created in CRM2011.

For setting the owner, we need to use the ‘AssignRequest‘. That is , we need to assign the record created to a User .

Here , for a AssignRequest class, the major fields / components are the ‘Assignee‘ and the ‘Target‘.

Assignee – is the system user to whom the entity has to be assigned.

Target – is the entity which needs to be assigned.

A straightforward example would be :

try
{
	// Create a new Row of Account
	Guid AccountGuid = _service.Create(objAccount);
	//Set Owner for Account which got created
	AssignRequest assignAcc = new AssignRequest
	{
		Assignee = new EntityReference(SystemUser.EntityLogicalName, new Guid(UserGuid.ToString())),
		Target = new EntityReference(Account.EntityLogicalName, new Guid(AccountGuid.ToString()))
	};
	// Execute the AssignRequest
	_service.Execute(assignAcc);
}
catch (SoapException ex)
{
	logger.WriteCRMSoapException("An error occurred during the Assign of an account", inquiry, ex);
}

This would set the OwnerId of the Account.
Hope it helps ! Thank You !

Advertisements

About mytechlifedays

Its been a wonderful learning period over the last 6 years in the IT industry , getting exposed to whole lot of technologies and ideas. The hurdles and the crisis that came along have been wonderful experience ... And now its time to pen them down so that let some others execute faster and easily with these information .....
This entry was posted in MS CRM and tagged , . Bookmark the permalink.

3 Responses to How to set OwnerId of any Record in CRM 2011

  1. Pingback: Assign Requests in Silverlight MS CRM SOAP Endpoint | My Tech Days

  2. The link points to API for CRM 3.0. Also, when I try to actually create an instance of AssignRequest, VS doesn’t find it. 🙂

Leave a Reply ! It would be always appreciated ! :)

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s