DYNAMICS 365 UPDATE RECORD OWNER AFTER ASSIGNREQUEST DEPRECATED
In a previous post, we saw
how to change record status in Dynamics 365 using C#
after the SetStateRequest message is deprecated.
In addition, when we wanted to update the owner of a record, we had to use the AssignRequest message to set it.
However, as you all know, the message AssignRequest is deprecated and in order to set the owner of a record,
you can now use the Update request without doing another specific call.
In this post, we will see the function on how to change record owner in Dynamics 365 using C#.
-
Below is the deprecated AssignRequest message used to set the owner of a record
public void AccountAssignRequest(Account account)
{
var assignRequest = new AssignRequest
{
Assignee = new EntityReference(SystemUser.EntityLogicalName, new Guid("USERGUID")),
Target = new EntityReference(Account.EntityLogicalName, account.Id)
};
AdminService.Execute(assignRequest);
}
-
Currently, to set the owner of a record you can use the Update message as below
public void AccountOwnerUpdate(Account account)
{
Account accountToUpdate = new Account
{
Id = account.Id,
Name = "Account Owner set using Update message",
OwnerId = new EntityReference(SystemUser.EntityLogicalName, new Guid("USERGUID")),
};
AdminService.Update(accountToUpdate);
}
Bonus Tip:
Don't forget to check and change the use of the AssignRequest in case you are migrating your environment.
Don't forget to check and change the use of the AssignRequest in case you are migrating your environment.
Hope This Helps!
Comments
Post a Comment