【问题标题】:Add member to marketing list in CRM 2011 plugin在 CRM 2011 插件中将成员添加到营销列表
【发布时间】:2012-05-15 14:40:01
【问题描述】:

我希望有人可以在这里帮助我。我找到了一篇文章,它为您提供了将添加多个实体(成员)添加到营销列表的一小段代码。到现在为止还挺好。我遇到了这个问题。我有一个自定义查找字段,它在营销成员列表中获取另一个营销列表(有联系人、客户或潜在客户)。现在我需要将这些成员迁移(添加)到我的新营销列表中。我的代码:

  1. AddListMembersListRequest request = new AddListMembersListRequest();
  2. request.ListId = Origmarketing_List_Id.Id;  
  3. request.MemberIds = new Guid[1];
  4. request.MemberIds[0] = guid;
  5. AddListMembersListResponse resp = (AddListMembersListResponse)service.Execute(request);   

第 2 行是我从 EntityReference 获得的 ID(查找字段获取另一个营销列表),现在我设置的第三和第四行是我真的很困惑但我仍然确定我是就在这里,因为我将它设置为listmemberid。在这个例子中,我只有一个原因,我想尝试一下它是如何工作的。第 4 行 bdw 中的 guid 获得了正确的值,它在我的代码顶部声明(我已经将它输出到另一个字段中,只是为了检查它是否获取了正确的值)。当您想添加多个实体时,也有人可以展示您将如何执行此操作吗?谢谢。我正在预操作(创建)上注册我的插件。而且插件本身不会引发任何错误,但它似乎没有在我的新列表中添加任何成员。如果有人能在这里帮助我,我将不胜感激。非常感谢你。

【问题讨论】:

    标签: c# dynamics-crm dynamics-crm-2011 crm


    【解决方案1】:

    首先,将事件更改为操作后,因为您还没有创建实体的GUID,事实上您也没有实体本身,这就是为什么它被称为操作前。 要添加多个实体,请尝试传递一个 GUIDs 数组,如下面的代码:

        // Setup the CrmConnection and OrganizationService instances
        CrmConnectionInstance = new CrmConnection(ConfigurationConstants.CrmConnectionName);
    OrgServiceInstance = new OrganizationService(CrmConnectionInstance);
        // Create the marketing list 
        Guid NewMarketingListId = Guid.Empty; 
        Microsoft.Xrm.Sdk.Entity CurrentList = new Microsoft.Xrm.Sdk.Entity(MarketingListConstants.MarketingListEntityName); 
        CurrentList[MarketingListConstants.MarketingListTypeAttribute] = false; 
        CurrentList[MarketingListConstants.ListNameAttribute] = "NameOfList"; 
        // For contacts, a value of 2 should be used. 
        CurrentList[MarketingListConstants.CreatedFromCodeAttribute] = new OptionSetValue(2); 
        // Actually create the list 
        NewMarketingListId = OrgServiceInstance.Create(CurrentList); 
        // Use the AddListMembersListRequest to add the members to the list 
        List<Guid> MemberListIds = new List<Guid>(); 
        // Now you'll need to add the Guids for each member to the list  
        // I'm leaving that part out as adding values to a list is very basic. 
        AddListMembersListRequest AddMemberRequest = new AddListMembersListRequest(); 
        AddMemberRequest.ListId = NewMarketingListId; 
        AddMemberRequest.MemberIds = memberIds.ToArray(); 
        // Use AddListMembersListReponse to get information about the request execution 
        AddListMembersListResponse AddMemberResponse = OrgServiceInstance.Execute(AddMemberRequest) as AddListMembersListResponse;
    

    【讨论】:

    • 您好,Grigory,非常感谢您的解决方案对我来说很好:-)。只是为了让你知道我犯了一个非常愚蠢的错误,我抓住了 listmemberid Guid 而不是 entityid Guid,这就是为什么我的记录从未被插入,但现在它工作正常。再次感谢,非常感谢您的努力。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-12
    相关资源
    最近更新 更多