简体   繁体   English

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

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

I hope there is someone who can help me out here. 我希望这里有人可以帮助我。 I have found an article which gives you the short piece of code to add Add Multiple Entities (Members) to a Marketing List. 我找到了一篇文章,该文章为您提供了将代码添加到营销列表中的添加多个实体(成员)的简短代码。 So far so good. 到现在为止还挺好。 I'm coming across this problem. 我遇到了这个问题。 I have a custom lookup field which gets another marketing list (has contacts, accounts or leads) inside the marketing member list. 我有一个自定义查找字段,该字段在行销成员列表内获取另一个行销列表(具有联系人,客户或潜在客户)。 Now I need to migrate (add) those members into my new marketing list. 现在,我需要将那些成员迁移(添加)到我的新营销列表中。 The code I have: 我有的代码:

  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);   

Line 2 is the ID I get from the EntityReference(Look Up field getting another Marketing List), now the third and fourth line I'm setting is something I'm really confused about but still I'm sure I'm going right here because I'm setting it to the listmemberid. 第2行是我从EntityReference(查找字段获得另一个营销列表)获得的ID,现在我要设置的第三和第四行确实让我感到困惑,但是我仍然确定我要在这里因为我将其设置为listmemberid。 In this example I just had one cause I wanted to try out how it works. 在这个例子中,我只是有一个原因,我想尝试一下它是如何工作的。 The guid in line 4 bdw gets the right value, it is declared at the top of my code(and I have output it on another field just to check it grabs the right value). 第4行bdw中的guid获取正确的值,它在我的代码的顶部声明(并且我已经在另一个字段上输出了它,只是为了检查它是否获取了正确的值)。 Also can someone please show how you would do this when you want to add multiple entities? 当有人要添加多个实体时,也可以请他人显示如何执行此操作吗? Thanks. 谢谢。 I'm registering my plugin on pre-operation(Create). 我正在预操作(创建)上注册我的插件。 And the plugin itself doesn't fire any errors, but it just doesn't seem to add any members on my new list. 插件本身不会引发任何错误,但似乎并没有在我的新列表中添加任何成员。 I would really much appreciate if somone could help me out here. 如果有人能在这里帮助我,我将非常感激。 Thank You Really Much in Advance. 真的非常感谢。

First of all, change event to post-operation, because you don't have the GUID of created entity yet, as a matter of fact you dont have the entity itself as well that's why it's called pre-operation. 首先,将事件更改为后期操作,因为您还没有所创建实体的GUID,实际上您也没有实体本身,这就是为什么将其称为操作前。 To add multiple entities try pass a GUIDs array like in code bellow: 要添加多个实体,请像下面的代码中那样传递一个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