Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assign new owner to appointment. "There should be only one owner party for an activity"

I need to change the owner of an appointment record when creating a new appointment. I'm using a plugin for the create message and i've found this code to assign a new owner to the appointment:

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 should be only one owner party for an activity

I guess i have to remove the current owner first and then assign the new owner. But how can i do this?

Thanks for any help!

like image 786
ThdK Avatar asked Aug 24 '11 09:08

ThdK


2 Answers

I was doing something similar with tasks (reassigning them in a plugin). As a "Update" plugin it didn't have any problems, but as "Create" it would fail with the message "There should be only one owner party for an activity"

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

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

This code goes in the Pre-operation stage.

like image 147
Eric Labashosky Avatar answered Oct 24 '22 15:10

Eric Labashosky


It looks like it is possible that some of the data may be corrupted. In this thread people are pushing the person to use SQL to directly delete some of the owners off of the activity - http://social.microsoft.com/Forums/en/crmdeployment/thread/d82cedee-e24e-4abc-9ec6-41306b89ed3b

This is only a possibility if you are using the on-premise model of Dynamics CRM 2011.

like image 32
cchamberlain Avatar answered Oct 24 '22 16:10

cchamberlain