更改 MS CRM 中所有约会的组织者

Change organizer in all appointments in MS CRM

我正在尝试使用插件更改约会中的组织者。 我有一个散列 table 来匹配应该用新的 guid 替换的 guid。 我有一个后备用户,当没有匹配项时我可以使用它

if (entity.Attributes.Contains("organizer"))
{
    var organizers = (EntityCollection)entity["organizer"];

    var record = (Entity)organizers.Entities[0];

    var organizer = (EntityReference)record["partyid"];
    // create activity party record
    Entity activityParty = new Entity();
    activityParty.LogicalName = "activityparty";

    EntityCollection colAP = new EntityCollection();
    colAP.Entities.Add(activityParty);


    if (guidHash.ContainsKey(organizer.Id.ToString()))
    {
        activityParty.Attributes["partyid"] = new EntityReference("systemuser", new Guid(guidHash[organizer.Id.ToString()]));
    }
    else
    {
        activityParty.Attributes["partyid"] = new EntityReference("systemuser", new Guid(migrationUserGuid));
    }
    entity.Attributes["organizer"] = new EntityCollection();
    entity.Attributes["organizer"] = colAP;
}

我在前操作步骤注册了插件,但是没有任何反应,用户还是老用户。

我设置 EntityCollection 的方式有问题吗?

假设插件被调用并且 guid 是正确的,您需要使用 Entity 的数组而不是 EntityCollection:

if (entity.Attributes.Contains("organizer"))
{
    var organizers = (EntityCollection)entity["organizer"];
    Entity record = organizers.Entities[0];
    EntityReference organizer = (EntityReference)record["partyid"];

    // create activity party record
    Entity activityParty = new Entity(activityparty");

    if (guidHash.ContainsKey(organizer.Id.ToString()))
    {
        activityParty["partyid"] = new EntityReference("systemuser", new Guid(guidHash[organizer.Id.ToString()]));
    }
    else
    {
        activityParty["partyid"] = new EntityReference("systemuser", new Guid(migrationUserGuid));
    }
    entity["organizer"] = new Entity[] { activityParty };
}