protected override void Execute(CodeActivityContext executionContext)
        {
            #region "Load CRM Service from context"

            Common objCommon = new Common(executionContext);
            objCommon.tracingService.Trace("Load CRM Service from context --- OK");
            #endregion

            #region "Read Parameters"
            EntityReference sourceList = this.SourceList.Get(executionContext);
            objCommon.tracingService.Trace(String.Format("marketingList: {0} ", sourceList.Id.ToString()));

            EntityReference targetList = this.TargetList.Get(executionContext);
            objCommon.tracingService.Trace(String.Format("campaign: {0} ", targetList.Id.ToString()));


            #endregion

            var request = new CopyMembersListRequest
            {
                SourceListId = sourceList.Id,
                TargetListId = targetList.Id
            };

            objCommon.service.Execute(request);
        }
示例#2
0
        /// <summary>
        /// Copy the members from the source list to the target list without creating duplicates. This works only with <c>Static List</c>.
        /// Please note that the type of entities contained in the source and target lists must match. If you're not sure about type of entities call <see cref="IsSameType(Guid, Guid)"/> to validate them.
        /// <para>
        /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.copymemberslistrequest(v=crm.7).aspx
        /// </para>
        /// </summary>
        /// <param name="sourceListId">Source Marketing List Id</param>
        /// <param name="targetListId">Target Marketing List Id</param>
        /// <returns>
        /// <see cref="CopyMembersListResponse"/>
        /// </returns>
        public CopyMembersListResponse CopyMembers(Guid sourceListId, Guid targetListId)
        {
            ExceptionThrow.IfGuidEmpty(sourceListId, "sourceListId");
            ExceptionThrow.IfGuidEmpty(targetListId, "targetListId");

            CopyMembersListRequest request = new CopyMembersListRequest()
            {
                SourceListId = sourceListId,
                TargetListId = targetListId
            };

            return((CopyMembersListResponse)this.OrganizationService.Execute(request));
        }
 private void CopyListWithData(CopyListParameters parameters)
 {
     WorkAsync(new WorkAsyncInfo
     {
         Message = "Copying Members",
         Work    = (w, ae) =>
         {
             CopyMembersListRequest req       = new CopyMembersListRequest();
             req.SourceListId                 = parameters.MarketingList.Id;
             req.TargetListId                 = parameters.NewListId;
             CopyMembersListResponse response = (CopyMembersListResponse)Service.Execute(req);
         },
         PostWorkCallBack = ae =>
         {
             ExecuteMethod(ProcessLoadLists);
         },
         ProgressChanged = ae =>
         {
             SetWorkingMessage(ae.UserState.ToString());
         }
     }
               );
 }
        private void CreateMarketingList()
        {
            Console.WriteLine("=== Creating the Marketing List ===");
            // Create the marketing list.  Make it static because members are going to be
            // added to the list.
            var list = new List
            {
                CreatedFromCode = new OptionSetValue((int)ListCreatedFromCode.Contact),
                ListName = "Sample Contact Marketing List",
                Type = MarketingListType.Static
            };
            
            _marketingListId = _serviceProxy.Create(list);

            NotifyEntityCreated(List.EntityLogicalName, _marketingListId);

            //<snippetDistributeCampaignFromMarketingList6>
            // Add a list of contacts to the marketing list.
            var addMemberListReq = new AddListMembersListRequest
            {
                MemberIds = new[] { _contactIdList[0], _contactIdList[2] },
                ListId = _marketingListId
            };

            _serviceProxy.Execute(addMemberListReq);

            Console.WriteLine("  Contacts with GUIDs \r\n\t{{{0}}}\r\n\tand {{{1}}}\r\n  were added to the list.",
                _contactIdList[0], _contactIdList[1]);
            //</snippetDistributeCampaignFromMarketingList6>

            //<snippetDistributeCampaignFromMarketingList7>
            // Copy the marketing list.  First create a new one, and then copy over the
            // members.
            list.ListName = list.ListName + " Copy";
            _copiedMarketingListId = _serviceProxy.Create(list);
            var copyRequest = new CopyMembersListRequest
            {
                SourceListId = _marketingListId,
                TargetListId = _copiedMarketingListId
            };

            _serviceProxy.Execute(copyRequest);
            //</snippetDistributeCampaignFromMarketingList7>

            //<snippetDistributeCampaignFromMarketingList8>
            // Add a single contact to the copied marketing list.
            var addMemberReq = new AddMemberListRequest
            {
                EntityId = _contactIdList[1],
                ListId = _copiedMarketingListId
            };

            _serviceProxy.Execute(addMemberReq);

            Console.WriteLine("  Contact with GUID\r\n\t{{{0}}}\r\n  was added to the list.",
                _contactIdList[1]);
            //</snippetDistributeCampaignFromMarketingList8>

            //<snippetDistributeCampaignFromMarketingList9>
            // Qualify the marketing list.
            var qualifyRequest = new QualifyMemberListRequest
            {
                OverrideorRemove = OverrideOrRemove.Override,
                MembersId = new[] { _contactIdList[0], _contactIdList[1] },
                ListId = _copiedMarketingListId
            };

            _serviceProxy.Execute(qualifyRequest);

            Console.WriteLine("  Qualified the copied marketing list so that it only\r\n    includes the first two members.");
            //</snippetDistributeCampaignFromMarketingList9>
        }
示例#5
0
        private void CreateMarketingList()
        {
            Console.WriteLine("=== Creating the Marketing List ===");
            // Create the marketing list.  Make it static because members are going to be
            // added to the list.
            var list = new List
            {
                CreatedFromCode = new OptionSetValue((int)ListCreatedFromCode.Contact),
                ListName        = "Sample Contact Marketing List",
                Type            = MarketingListType.Static
            };

            _marketingListId = _serviceProxy.Create(list);

            NotifyEntityCreated(List.EntityLogicalName, _marketingListId);

            //<snippetDistributeCampaignFromMarketingList6>
            // Add a list of contacts to the marketing list.
            var addMemberListReq = new AddListMembersListRequest
            {
                MemberIds = new[] { _contactIdList[0], _contactIdList[2] },
                ListId    = _marketingListId
            };

            _serviceProxy.Execute(addMemberListReq);

            Console.WriteLine("  Contacts with GUIDs \r\n\t{{{0}}}\r\n\tand {{{1}}}\r\n  were added to the list.",
                              _contactIdList[0], _contactIdList[1]);
            //</snippetDistributeCampaignFromMarketingList6>

            //<snippetDistributeCampaignFromMarketingList7>
            // Copy the marketing list.  First create a new one, and then copy over the
            // members.
            list.ListName          = list.ListName + " Copy";
            _copiedMarketingListId = _serviceProxy.Create(list);
            var copyRequest = new CopyMembersListRequest
            {
                SourceListId = _marketingListId,
                TargetListId = _copiedMarketingListId
            };

            _serviceProxy.Execute(copyRequest);
            //</snippetDistributeCampaignFromMarketingList7>

            //<snippetDistributeCampaignFromMarketingList8>
            // Add a single contact to the copied marketing list.
            var addMemberReq = new AddMemberListRequest
            {
                EntityId = _contactIdList[1],
                ListId   = _copiedMarketingListId
            };

            _serviceProxy.Execute(addMemberReq);

            Console.WriteLine("  Contact with GUID\r\n\t{{{0}}}\r\n  was added to the list.",
                              _contactIdList[1]);
            //</snippetDistributeCampaignFromMarketingList8>

            //<snippetDistributeCampaignFromMarketingList9>
            // Qualify the marketing list.
            var qualifyRequest = new QualifyMemberListRequest
            {
                OverrideorRemove = OverrideOrRemove.Override,
                MembersId        = new[] { _contactIdList[0], _contactIdList[1] },
                ListId           = _copiedMarketingListId
            };

            _serviceProxy.Execute(qualifyRequest);

            Console.WriteLine("  Qualified the copied marketing list so that it only\r\n    includes the first two members.");
            //</snippetDistributeCampaignFromMarketingList9>
        }