locked
bulk deletion in crm RRS feed

  • Question

  • good day! does anybody here knows how to code a bulk deletion in crm? my head is aching with this.. 

     

    Thank you in advance.

     

    Hope to hear an answer. :(

    Monday, May 2, 2011 8:34 AM

Answers

  • Hi twinkle,

    For CRM 2011 check the following link http://blogs.infinite-x.net/2011/05/02/crm-2011-exploring-bulk-delete-operations/

    for CRM 4.0 You can write a console application using the crm sdk like,


            static void runBulkDelete(CrmService service)
            {
                // Create a query expression using the QueryExpressionHelper
                QueryExpressionHelper expression = new QueryExpressionHelper("asyncoperation");
                expression.Columns.AddColumn("asyncoperationid");
                expression.Criteria.Conditions.AddCondition("statecode", ConditionOperator.Equal, (int)AsyncOperationState.Completed);
                expression.Criteria.Conditions.AddCondition("completedon", ConditionOperator.OlderThanXMonths, 1);
                expression.Criteria.Conditions.AddCondition("operationtype", ConditionOperator.NotEqual, (int)AsyncOperationType.Import);

                Guid[] emptyRecipients = new Guid[0];
                BulkDeleteRequest request = new BulkDeleteRequest();
                request.JobName = "Bulk delete completed asyncoperations to free up space";
                request.QuerySet = new QueryBase[] { expression.Query };
                request.ToRecipients = emptyRecipients;
                request.CCRecipients = emptyRecipients;
                request.SendEmailNotification = false;
                request.RecurrencePattern = string.Empty;
                request.StartDateTime = CrmDateTime.Now;

                BulkDeleteResponse response = (BulkDeleteResponse)service.Execute(request);

                Console.WriteLine("Bulk delete job with id: {0} has been created", response.JobId);
                Console.ReadLine();
            }

     

    Regards,

    • Proposed as answer by Edwin2win Tuesday, May 3, 2011 8:28 AM
    • Marked as answer by twinkle0903 Thursday, May 5, 2011 6:00 AM
    Tuesday, May 3, 2011 8:03 AM

All replies

  • Hi twinkle,

    For CRM 2011 check the following link http://blogs.infinite-x.net/2011/05/02/crm-2011-exploring-bulk-delete-operations/

    for CRM 4.0 You can write a console application using the crm sdk like,


            static void runBulkDelete(CrmService service)
            {
                // Create a query expression using the QueryExpressionHelper
                QueryExpressionHelper expression = new QueryExpressionHelper("asyncoperation");
                expression.Columns.AddColumn("asyncoperationid");
                expression.Criteria.Conditions.AddCondition("statecode", ConditionOperator.Equal, (int)AsyncOperationState.Completed);
                expression.Criteria.Conditions.AddCondition("completedon", ConditionOperator.OlderThanXMonths, 1);
                expression.Criteria.Conditions.AddCondition("operationtype", ConditionOperator.NotEqual, (int)AsyncOperationType.Import);

                Guid[] emptyRecipients = new Guid[0];
                BulkDeleteRequest request = new BulkDeleteRequest();
                request.JobName = "Bulk delete completed asyncoperations to free up space";
                request.QuerySet = new QueryBase[] { expression.Query };
                request.ToRecipients = emptyRecipients;
                request.CCRecipients = emptyRecipients;
                request.SendEmailNotification = false;
                request.RecurrencePattern = string.Empty;
                request.StartDateTime = CrmDateTime.Now;

                BulkDeleteResponse response = (BulkDeleteResponse)service.Execute(request);

                Console.WriteLine("Bulk delete job with id: {0} has been created", response.JobId);
                Console.ReadLine();
            }

     

    Regards,

    • Proposed as answer by Edwin2win Tuesday, May 3, 2011 8:28 AM
    • Marked as answer by twinkle0903 Thursday, May 5, 2011 6:00 AM
    Tuesday, May 3, 2011 8:03 AM
  • thank you, :)

     

    Thursday, May 5, 2011 6:00 AM
  • :) Your welcome twinkle.
    Thursday, May 5, 2011 5:48 PM
  • There is also a tool build to kick off bulk deletions in CRM 4.0 as well.  It works well.

    http://blog.arkesystems.com/post/2011/04/CRM-40-Bulk-Delete-Tool.aspx

    Thursday, May 5, 2011 6:18 PM
  • :)) hope you can help me with other problem that i would encounter :)
    Friday, May 6, 2011 1:44 AM