2012-05-15 113 views
2

我希望有人能够帮助我。我找到了一篇文章,其中提供了一小段代码,用于将添加多个实体(成员)添加到市场营销列表。到现在为止还挺好。我遇到了这个问题。我有一个自定义的查询字段,可以在营销成员列表中获取另一个营销列表(包含联系人,帐户或潜在客户)。现在我需要将这些成员迁移(添加)到我的新营销列表中。我的代码有:将会员添加到CRM 2011插件中的营销列表

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号线是我的ID从得到的EntityReference(查找场得到另一个营销列表),现在是三,四线我设置的东西我真的困惑,但我仍然确信我会在这里,因为我把它设置到listmemberid。在这个例子中,我只有一个原因,我想试试它的工作原理。第4行bdw中的guid获得正确的值,它在我的代码的顶部声明(并且我已经在另一个域上输出它来检查它是否抓取正确的值)。也可以有人请说明当你想添加多个实体时你会怎么做?谢谢。我正在注册我的插件在预操作(创建)。而插件本身不会引发任何错误,但它似乎并没有在我的新列表中添加任何成员。如果somone能帮助我,我真的很感激。非常感谢你提前。

回答

4

首先,将事件更改为后期操作,因为您还没有创建实体的GUID,事实上,您也没有实体本身,这就是为什么它被称为预操作。 要添加多个实体试图在代码中传递的GUID阵列状波纹管:

// 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; 
+0

嗨格里戈里,非常感谢你为你的解决方案为我工作得很好:-)。只是为了让你知道我犯了一个非常愚蠢的错误,我抓住listmemberid Guid而不是entityid Guid,这就是为什么我的记录从未插入,但现在它的工作正常。再次感谢,非常感谢您的努力。 –

相关问题