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

*爱你&永不变心* 提交于 2019-12-01 05:48:17

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.

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.

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;
                }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!