在MS CRM中的所有约会中更改管理器

时间:2015-09-06 06:47:51

标签: collections crm microsoft-dynamics

我试图用插件更改约会中的组织者。 我有一个哈希表来匹配要用新的替换的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的方式有问题吗?

1 个答案:

答案 0 :(得分:0)

假设调用插件并且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 };
}