Assign a new owner for the appointment. "There must be only one owner for the activity"

I need to change the owner of the appointment record when creating a new appointment. I use the plugin to create message, and I found this code to assign a new owner to the meeting:

entity = context.PostEntityImages["PostImage"]; ...... AssignRequest request = new AssignRequest(); //request.RequestName request.Assignee = new EntityReference("systemuser", owners.ToList()[0].Id); request.Target = new EntityReference(Appointment.EntityLogicalName, entity.Id); service.Execute(request); 

But when I test this, I get the following error: Invalid argument: there must be only one owner for the activity.

I think I need to remove the current owner first and then appoint a new owner. But how can I do this?

Thanks for any help!

+4
source share
3 answers

I did something similar with tasks (reassigning them in the plugin). He had no problems as an “Update” plugin, but, like “Create”, he failed with the message “There must be only one owner for the activity”

To fix this change, the "Create" plugin simply install ownerid (instead of executing AssignRequest).

 targetEntity.Attributes["ownerid"] = new EntityReference(SystemUser.EntityLogicalName, assignTo.Id); 

This code goes to the preprocessing phase.

+4
source

It looks like some data may be corrupted. In this thread, people force a person to use SQL to directly remove some of the owners from activity - http://social.microsoft.com/Forums/en/crmdeployment/thread/d82cedee-e24e-4abc-9ec6-41306b89ed3b

This is only an option if you are using the local Dynamics CRM 2011 model.

+1
source
 Guid id= new Guid("{33011A68-D311-E211-A429-005056820002}"); switch (context.MessageName) { case "Update": { try { if (ent.Contains("fieldname") == true) { AssignRequest assign = new AssignRequest { Assignee = new EntityReference("systemuser", id), Target = new EntityReference(ent.LogicalName, ent.Id) }; _service.Execute(assign); } } catch (Exception ex) { throw new InvalidPluginExecutionException("Error" + Environment.NewLine + "Details: " + ex.Message); } } break; } 
0
source

All Articles