繁体   English   中英

将成员添加到CRM 2011插件的营销列表中

[英]Add member to marketing list in CRM 2011 plugin

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

  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获取正确的值,它在我的代码的顶部声明(并且我已经在另一个字段上输出了它,只是为了检查它是否获取了正确的值)。 当有人要添加多个实体时,也可以请他人显示如何执行此操作吗? 谢谢。 我正在预操作(创建)上注册我的插件。 插件本身不会引发任何错误,但似乎并没有在我的新列表中添加任何成员。 如果有人能在这里帮助我,我将非常感激。 真的非常感谢。

首先,将事件更改为后期操作,因为您还没有所创建实体的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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM