Answered by:
Changing Owner of a record

Question
-
Hi,
I am able to assign Owner of a record of type OWNER while creating of the record using crmwebservice in C# code. But I cannot update the owner. My code is as follows:
string [] strSalesMan = new string[2];
strSalesMan = RetrieveOwnerGUID(CRMWebServiceObject, ownername); // this method returns two values from scrm in a string array :
// ownerid.Value and ownerid.nameOwner objSalesmancode = new Owner();
objSalesmancode.type = "systemuser";
objSalesmancode.Value = new Guid(strSalesMan[0].ToString());
objSalesmancode.name = strSalesMan[1].ToString();
objSalesmancode.IsNull = false;
objSalesmancode.IsNullSpecified = true;
same code is working for creating record, but not able to update owner. suggestion required how to go ahead.
regards
joonTuesday, March 9, 2010 8:16 AM
Answers
-
use the "Assign Message".
// Create the SecurityPrincipal object.
SecurityPrincipal assignee = new SecurityPrincipal();
assignee.Type = SecurityPrincipalType.User;
// PrincipalId is some known Guid belonging to the user or team that will own this record.
assignee.PrincipalId = new Guid("326A0053-71CB-465E-9BEB-633E2E0851A9");
// Create the target object for the request.
TargetOwnedAccount target = new TargetOwnedAccount();
// Set the properties of the target object.
// EntityId is some known Guid belonging to the account that is being assigned to the user.
target.EntityId = new Guid("2B951FBC-1C56-4430-B23B-20A1349068F3");
// Create the request object.
AssignRequest assign = new AssignRequest();
// Set the properties of the request object.
assign.Assignee = assignee;
assign.Target = target;
// Execute the request.
AssignResponse assignResponse = (AssignResponse)service.Execute(assign);
Muhammad Ali Khan
My MS CRM blog- Proposed as answer by Muhammad Ali Khan Tuesday, March 9, 2010 9:07 AM
- Marked as answer by Donna EdwardsMVP Thursday, March 11, 2010 5:38 PM
Tuesday, March 9, 2010 8:26 AM
All replies
-
use the "Assign Message".
// Create the SecurityPrincipal object.
SecurityPrincipal assignee = new SecurityPrincipal();
assignee.Type = SecurityPrincipalType.User;
// PrincipalId is some known Guid belonging to the user or team that will own this record.
assignee.PrincipalId = new Guid("326A0053-71CB-465E-9BEB-633E2E0851A9");
// Create the target object for the request.
TargetOwnedAccount target = new TargetOwnedAccount();
// Set the properties of the target object.
// EntityId is some known Guid belonging to the account that is being assigned to the user.
target.EntityId = new Guid("2B951FBC-1C56-4430-B23B-20A1349068F3");
// Create the request object.
AssignRequest assign = new AssignRequest();
// Set the properties of the request object.
assign.Assignee = assignee;
assign.Target = target;
// Execute the request.
AssignResponse assignResponse = (AssignResponse)service.Execute(assign);
Muhammad Ali Khan
My MS CRM blog- Proposed as answer by Muhammad Ali Khan Tuesday, March 9, 2010 9:07 AM
- Marked as answer by Donna EdwardsMVP Thursday, March 11, 2010 5:38 PM
Tuesday, March 9, 2010 8:26 AM -
hi Muhammad,
thankx a lot for your reply. it worked.
but can i update owner along with other records also??
i am using "CRMWebServiceObject.Update(EntityObject)" to update the whole record.
i want update to be done using only one method. here i am hitting the crmwebservice two times: Update and Execute.
can i use "AssignResponse assignResponse = (AssignResponse)service.Execute(assign)" to update other records also??
regards
joonTuesday, March 9, 2010 8:52 AM -
Hi
I don't think so. i am not sure why they don't provide update of owner in crmService.Update().
it's strange.
Even in the WebUI while create you can change the owner. but while update a dialog popup where you have to select the owner.
so I think for normal attributes update use the crmService.Update()
and for owner update use the Assign Message.
yeah it's weird :(.
Muhammad Ali Khan
My MS CRM blogTuesday, March 9, 2010 9:06 AM -
:)
any ways, thanx for your reply. it was helpful.
regards
joonTuesday, March 9, 2010 9:23 AM -
Hi,
I am getting the below error while changing the owner of the Lead record, not for all the Lead records for only few records it is showing like this "Insufficient Permission" You do not have permission to access these records. Contact your Microsoft Dynamics CRM administrator. I am the Administrator but it is showing like this. could you let me know the solution for this? I have tried my best but I am not able to solve this one.
Bujji
Wednesday, February 5, 2014 3:32 PM