Пример #1
0
        /// <summary>
        /// This method creates Quick Campaign for a given Marketing List and retruns the
        /// Guid of the Quich Campaign which is modelled as bulk operation in CRM
        /// </summary>
        /// <param name="activityEntity">
        /// An object that indicates activity type for the quick campaign and
        /// contains values for each activity that will be created
        /// </param>
        /// <param name="marketingListId">
        /// The ID of the marketing list to which quick campaign is distributed
        /// </param>
        /// <param name="ownershipOption">
        /// Specifies who will own the activities created by the Quick Campaign
        ///	The PropagationOwnershipOptions enum is used to specify value for this parameter
        ///	</param>
        /// <param name="isPropagate">
        /// Specifies whether the operation is to be executed.
        /// This input is often 'true' for Quick Campaign
        /// </param>
        public static Guid CreateAndRetrieveQuickCampaignForMarketingList(CrmServiceClient service,
                                                                          Entity letterActivityEntity,
                                                                          Guid marketingListId,
                                                                          PropagationOwnershipOptions ownershipOption,
                                                                          bool isPropagate)
        {
            //Create the request object from input parameters
            var request = new CreateActivitiesListRequest()
            {
                Activity          = letterActivityEntity,
                ListId            = marketingListId,
                OwnershipOptions  = ownershipOption,
                Propagate         = isPropagate,
                TemplateId        = Guid.Empty,
                FriendlyName      = "Quick Campaign for My List",
                Owner             = new EntityReference("systemuser", _currentUser),
                PostWorkflowEvent = true
            };

            //Execute the request
            var response =
                (CreateActivitiesListResponse)service.Execute(request);

            //On executing the request a BulkOperation record would be created in CRM.
            //If isPropagate is true, a corresponding Async job is also created which runs and creates the required activities
            //The response has BulkOperationId. This is the Id of the bulkoperation that mimics QuickCampaign in CRM
            Guid BOId = response.BulkOperationId;

            System.Console.WriteLine(
                "Quick Campaign with following name has been created. "
                + "Please verify manually: \n"
                + request.FriendlyName
                + "\nPress enter to continue....");
            System.Console.ReadLine();

            return(BOId);
        }
Пример #2
0
        /// <summary>
        /// This method creates a Quick Campaign for a set of accounts selected by a query
        /// </summary>
        /// <param name="activityEntity">
        /// An object that indicates activity type for the quick campaign and
        /// contains values for each of activity that will be created
        /// </param>
        /// <param name="query">
        /// A query that provides a list of accounts for which
        /// the quick campaign is distributed.
        /// </param>
        /// <param name="ownershipOption">
        /// Specifies who will own the activities created by the Quick Campaign
        ///	The PropagationOwnershipOptions enum is used to specify value for this parameter
        ///	</param>
        /// <param name="isPropagate">
        /// Specifies whether the operation is to be executed.
        /// This input is often 'true' for Quick Campaign
        /// </param>
        /// <returns></returns>
        public static Guid CreateAndRetrieveQuickCampaignForQueryExpression(CrmServiceClient service, Entity emailActivityEntity,
                                                                            QueryExpression query, PropagationOwnershipOptions ownershipOption, bool isPropagate)
        {
            // create the bulkoperation
            var request = new PropagateByExpressionRequest()
            {
                Activity           = emailActivityEntity,
                ExecuteImmediately = false, // Default value.
                FriendlyName       = "Query Based Quick Campaign",
                OwnershipOptions   = ownershipOption,
                QueryExpression    = query,
                Owner             = new EntityReference("systemuser", _currentUser),
                PostWorkflowEvent = true,
                SendEmail         = false,
                TemplateId        = Guid.Empty
            };

            var response =
                (PropagateByExpressionResponse)service.Execute(request);

            Guid bulkOpId = response.BulkOperationId;

            System.Console.WriteLine(
                "Quick Campaign with following name has been created. "
                + "Please verify manually: \n"
                + request.FriendlyName + "\nPress enter to continue....");
            System.Console.ReadLine();
            return(bulkOpId);
        }
Пример #3
0
        //</snippetQuickCampaign2> 

        //<snippetQuickCampaign3> 
        /// <summary>
        /// This method creates Quick Campaign for a given Marketing List and retruns the 
        /// Guid of the Quich Campaign which is modelled as bulk operation in CRM
        /// </summary>
        /// <param name="activityEntity">
        /// An object that indicates activity type for the quick campaign and 
        /// contains values for each activity that will be created
        /// </param>
        /// <param name="marketingListId">
        /// The ID of the marketing list to which quick campaign is distributed
        /// </param>
        /// <param name="ownershipOption">
        /// Specifies who will own the activities created by the Quick Campaign
        ///	The PropagationOwnershipOptions enum is used to specify value for this parameter
        ///	</param>
        /// <param name="isPropagate">
        /// Specifies whether the operation is to be executed. 
        /// This input is often 'true' for Quick Campaign
        /// </param>				
        public Guid CreateAndRetrieveQuickCampaignForMarketingList(
            Entity letterActivityEntity, 
            Guid marketingListId, 
            PropagationOwnershipOptions ownershipOption, 
            bool isPropagate)
        {
            //Create the request object from input parameters
            CreateActivitiesListRequest request = new CreateActivitiesListRequest() {
                Activity = letterActivityEntity,
                ListId = marketingListId,
                OwnershipOptions = ownershipOption,
                Propagate = isPropagate,
                TemplateId = Guid.Empty,
                FriendlyName = "Quick Campaign for My List",
                Owner = new EntityReference("systemuser", _currentUser),
                PostWorkflowEvent = true
            };

            //Execute the request
            CreateActivitiesListResponse response = 
                (CreateActivitiesListResponse)_serviceProxy.Execute(request);

            //On executing the request a BulkOperation record would be created in CRM. 
            //If isPropagate is true, a corresponding Async job is also created which runs and creates the required activities 
            //The response has BulkOperationId. This is the Id of the bulkoperation that mimics QuickCampaign in CRM
            Guid BOId = response.BulkOperationId;
            System.Console.WriteLine(
                "Quick Campaign with following name has been created. " 
                + "Please verify in Web app manually: \n" 
                + request.FriendlyName 
                + "\nPress enter to continue....");
            System.Console.ReadLine();

            return BOId;

        } 
Пример #4
0
        //<snippetQuickCampaign2> 
        /// <summary>
        /// This method creates a Quick Campaign for a set of accounts selected by a query
        /// </summary>
        /// <param name="activityEntity">
        /// An object that indicates activity type for the quick campaign and 
        /// contains values for each of activity that will be created
        /// </param>
        /// <param name="query">
        /// A query that provides a list of accounts for which 
        /// the quick campaign is distributed.
        /// </param>
        /// <param name="ownershipOption">
        /// Specifies who will own the activities created by the Quick Campaign
        ///	The PropagationOwnershipOptions enum is used to specify value for this parameter
        ///	</param>
        /// <param name="isPropagate">
        /// Specifies whether the operation is to be executed. 
        /// This input is often 'true' for Quick Campaign
        /// </param>        
        /// <returns></returns>
        public Guid CreateAndRetrieveQuickCampaignForQueryExpression(Entity emailActivityEntity, 
            QueryExpression query, PropagationOwnershipOptions ownershipOption, bool isPropagate)
        {
            
            // create the bulkoperation
            PropagateByExpressionRequest request = new PropagateByExpressionRequest() {
                Activity = emailActivityEntity,
                ExecuteImmediately = false, // Default value.
                FriendlyName = "Query Based Quick Campaign",
                OwnershipOptions = ownershipOption,
                QueryExpression = query,
                Owner = new EntityReference("systemuser", _currentUser),
                PostWorkflowEvent = true,
                SendEmail = false,
                TemplateId = Guid.Empty
            };

            PropagateByExpressionResponse response = 
                (PropagateByExpressionResponse)_serviceProxy.Execute(request);

            Guid bulkOpId = response.BulkOperationId;
            System.Console.WriteLine(
                "Quick Campaign with following name has been created. "
                + "Please verify in Web app manually: \n" 
                + request.FriendlyName + "\nPress enter to continue....");
            System.Console.ReadLine();
            return bulkOpId;

        }
        /// <summary>
        /// Distribute <c>CampaignActivity</c>.
        /// Creates the appropriate activity for each member in the list for the specified campaign activity.
        /// <para>
        /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.distributecampaignactivityrequest(v=crm.8).aspx
        /// </para>
        /// </summary>
        /// <param name="id"><c>CampaignActvity</c> Id</param>
        /// <param name="activityEntity"><c>Activity</c> to be distributed.
        /// This should be <c>phonecall</c> - <c>appointment</c> - <c>letter</c> - <c>fax</c> - <c>email</c>.
        /// </param>
        /// <param name="propagationOwnershipOptions">
        /// <c>Ownership</c> options for the activity
        /// This parameter 's values are;
        /// <c>Caller</c> : All created activities are assigned to the caller of <see cref="IOrganizationService"/>
        /// <c>ListMemberOwner</c> : Created activities are assigned to respective owners of target members.
        /// <c>None</c> : There is no change in ownership for the created activities.
        /// <para>
        /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.propagationownershipoptions(v=crm.8).aspx
        /// </para>
        /// </param>
        /// <param name="ownerTypeCode"></param>
        /// <param name="ownerId"></param>
        /// <param name="queueId">
        /// Set this field if you want also add created activities to an <c>Queue</c>.
        /// Method throws an exception (<see cref="ExceptionThrow.IfGuidEmpty(Guid, string, string)"/>) if you set this field to <see cref="Guid.Empty"/>
        /// </param>
        /// <param name="emailTemplateId">
        /// If you distribute <c>CampaignActivity</c> with <c>Email</c> and you want to use existing <c>template</c> set this field.
        /// Method throws an exception (<see cref="ExceptionThrow.IfGuidEmpty(Guid, string, string)"/>) if you set this field to <see cref="Guid.Empty"/>
        /// </param>
        /// <param name="doesPropagate">
        /// Set <c>true</c>, whether the activity is both created and executed. Otherwise set <c>false</c>.
        /// This field's default value is <c>true</c>, so activity will be created and executed (exp: email wil be send)
        /// </param>
        /// <param name="useAsync">
        /// Set <c>true</c>, if you want use an asynchronous job to distribute activities. Otherwise set <c>false</c>.
        /// This field's default value is <c>true</c>
        /// </param>
        /// <param name="sendEmail">
        /// Set <c>true</c> if you distribute <c>CampaignActivity</c> with <c>Email</c> and you want to send created activities.
        /// </param>
        /// <param name="validateActivity">
        /// Validates activity entity with required attributes and using method's enum values
        /// </param>
        /// <returns>
        /// Returns created <c>BulkOperation</c> Id in <see cref="DistributeCampaignActivityResponse.BulkOperationId"/> property.
        /// </returns>
        public DistributeCampaignActivityResponse Distribute(Guid id, Entity activityEntity, PropagationOwnershipOptions propagationOwnershipOptions, PrincipalType ownerTypeCode, Guid ownerId, Guid?queueId, Guid?emailTemplateId, bool doesPropagate = true, bool useAsync = true, bool sendEmail = false, bool validateActivity = true)
        {
            ExceptionThrow.IfGuidEmpty(id, "id");
            ExceptionThrow.IfGuidEmpty(ownerId, "ownerId");

            ValidateEntity(activityEntity);

            if (validateActivity)
            {
                ValidateActivity(id, activityEntity.LogicalName);
            }

            DistributeCampaignActivityRequest request = new DistributeCampaignActivityRequest()
            {
                CampaignActivityId = id,
                Activity           = activityEntity,
                Owner             = new EntityReference(ownerTypeCode.Description(), ownerId),
                OwnershipOptions  = propagationOwnershipOptions,
                PostWorkflowEvent = useAsync,
                Propagate         = doesPropagate,
                SendEmail         = sendEmail
            };

            if (queueId.HasValue)
            {
                ExceptionThrow.IfGuidEmpty(queueId.Value, "queueId");

                request.QueueId = queueId.Value;
            }

            if (emailTemplateId.HasValue)
            {
                ExceptionThrow.IfGuidEmpty(emailTemplateId.Value, "emailTemplateId");

                request.TemplateId = emailTemplateId.Value;
            }

            return((DistributeCampaignActivityResponse)this.OrganizationService.Execute(request));
        }
        /// <summary>
        /// Distribute <c>CampaignActivity</c> with <c>Email</c> activity.
        /// </summary>
        /// <param name="id"><c>CampaignActvity</c> Id</param>
        /// <param name="fromType">Email <c>From</c> (<see cref="FromEntityType"/>)</param>
        /// <param name="fromId">Email <c>From</c> Id</param>
        /// <param name="subject">Email Subject</param>
        /// <param name="body">Email Body</param>
        /// <param name="emailTemplateId">
        /// If you want to use existing <c>template</c> set this field.
        /// Method throws an exception (<see cref="ExceptionThrow.IfGuidEmpty(Guid, string, string)"/>) if you set this field to <see cref="Guid.Empty"/>
        /// </param>
        /// <param name="sendEmail">
        /// Set <c>true</c> if you want to send created activities.
        /// </param>
        /// <param name="propagationOwnershipOptions"></param>
        /// <param name="ownerTypeCode"></param>
        /// <param name="ownerId"></param>
        /// <param name="queueId"></param>
        /// <param name="doesPropagate">Set <c>true</c>, whether the activity is both created and executed. Otherwise set <c>false</c>.</param>
        /// <param name="useAsync">
        /// Set <c>true</c>, whether the activity is both created and executed. Otherwise set <c>false</c>.
        /// This field's default value is <c>true</c>, so activity will be created and executed (exp: email wil be send)
        /// </param>
        /// <param name="validateActivity"></param>
        /// <returns>
        /// Returns created <c>BulkOperation</c> Id in <see cref="DistributeCampaignActivityResponse.BulkOperationId"/> property.
        /// </returns>
        public DistributeCampaignActivityResponse DistributeByEmail(Guid id, FromEntityType fromType, Guid fromId, string subject, string body, Guid?emailTemplateId, bool sendEmail, PropagationOwnershipOptions propagationOwnershipOptions, PrincipalType ownerTypeCode, Guid ownerId, Guid?queueId, bool doesPropagate = true, bool useAsync = true, bool validateActivity = true)
        {
            ExceptionThrow.IfGuidEmpty(fromId, "fromId");

            Entity from = new Entity("activityparty");

            from["partyid"] = new EntityReference(fromType.Description(), fromId);

            Entity entity = new Entity("email");

            entity["from"] = new[] { from };

            if (emailTemplateId.HasValue)
            {
                ExceptionThrow.IfGuidEmpty(emailTemplateId.Value, "templateId");
            }
            else
            {
                ExceptionThrow.IfNullOrEmpty(subject, "subject");
                ExceptionThrow.IfNullOrEmpty(body, "body");

                entity["subject"]     = subject;
                entity["description"] = body;
            }

            return(Distribute(id, entity, propagationOwnershipOptions, ownerTypeCode, ownerId, queueId, emailTemplateId, doesPropagate, useAsync, sendEmail, validateActivity));
        }
        /// <summary>
        /// Distribute <c>CampaignActivity</c> with <c>Appointment</c>.
        /// </summary>
        /// <param name="id"><c>CampaignActvity</c> Id</param>
        /// <param name="subject">Appointment Subject</param>
        /// <param name="location">Appointment Location</param>
        /// <param name="description">Appointment Description</param>
        /// <param name="scheduledStart">Appointment Start date</param>
        /// <param name="scheduledEnd">Appointment End date</param>
        /// <param name="isAllDayEvent">
        /// Set <c>true</c> if this event for all day
        /// </param>
        /// <param name="propagationOwnershipOptions"></param>
        /// <param name="ownerTypeCode"></param>
        /// <param name="ownerId"></param>
        /// <param name="queueId"></param>
        /// <param name="doesPropagate">Set <c>true</c>, whether the activity is both created and executed. Otherwise set <c>false</c>.</param>
        /// <param name="useAsync">
        /// Set <c>true</c>, if you want use an asynchronous job to distribute activities. Otherwise set <c>false</c>.
        /// This field's default value is <c>true</c>.
        /// </param>
        /// <param name="validateActivity"></param>
        /// <returns>
        /// Returns created <c>BulkOperation</c> Id in <see cref="DistributeCampaignActivityResponse.BulkOperationId"/> property.
        /// </returns>
        public DistributeCampaignActivityResponse DistributeByAppointment(Guid id, string subject, string location, string description, DateTime scheduledStart, DateTime scheduledEnd, bool isAllDayEvent, PropagationOwnershipOptions propagationOwnershipOptions, PrincipalType ownerTypeCode, Guid ownerId, Guid?queueId, bool doesPropagate = true, bool useAsync = true, bool validateActivity = true)
        {
            ExceptionThrow.IfNullOrEmpty(subject, "subject");
            ExceptionThrow.IfEquals(scheduledStart, "scheduledStart", DateTime.MinValue);
            ExceptionThrow.IfEquals(scheduledEnd, "scheduledEnd", DateTime.MinValue);

            Entity entity = new Entity("appointment");

            entity["subject"]        = subject;
            entity["location"]       = location;
            entity["isalldayevent"]  = isAllDayEvent;
            entity["scheduledstart"] = scheduledStart;
            entity["scheduledend"]   = scheduledEnd;
            entity["description"]    = description;

            return(Distribute(id, entity, propagationOwnershipOptions, ownerTypeCode, ownerId, queueId, null, doesPropagate, useAsync, false, validateActivity));
        }
        /// <summary>
        /// Distribute <c>CampaignActivity</c> with <c>Fax</c> activity.
        /// </summary>
        /// <param name="id"><c>CampaignActvity</c> Id</param>
        /// <param name="subject">Fax subject</param>
        /// <param name="description">Fax description</param>
        /// <param name="propagationOwnershipOptions"></param>
        /// <param name="ownerTypeCode"></param>
        /// <param name="ownerId"></param>
        /// <param name="queueId"></param>
        /// <param name="doesPropagate">Set <c>true</c>, whether the activity is both created and executed. Otherwise set <c>false</c>.</param>
        /// <param name="useAsync">
        /// Set <c>true</c>, if you want use an asynchronous job to distribute activities. Otherwise set <c>false</c>.
        /// This field's default value is <c>true</c>.
        /// </param>
        /// <param name="validateActivity"></param>
        /// <returns>
        /// Returns created <c>BulkOperation</c> Id in <see cref="DistributeCampaignActivityResponse.BulkOperationId"/> property.
        /// </returns>
        public DistributeCampaignActivityResponse DistributeByFax(Guid id, string subject, string description, PropagationOwnershipOptions propagationOwnershipOptions, PrincipalType ownerTypeCode, Guid ownerId, Guid?queueId, bool doesPropagate = true, bool useAsync = true, bool validateActivity = true)
        {
            ExceptionThrow.IfNullOrEmpty(subject, "subject");

            Entity entity = new Entity("fax");

            entity["subject"]     = subject;
            entity["description"] = description;

            return(Distribute(id, entity, propagationOwnershipOptions, ownerTypeCode, ownerId, queueId, null, doesPropagate, useAsync, false, validateActivity));
        }