[CRM 4] Bulk Deletion Jobs tool

A Bulk Deletion Job is an asynchronous operation in CRM to delete a set of records according to a custom query. This is very useful when you have a CRM where hundreds of users are inserting and editing records constantly and you want to keep the performance of your CRM database.

In CRM 4, It’s not possible to create Bulk Deletion Jobs manually from CRM web interface (or CRM Outlook client). However, I’ve created a tool, which can be integrated in CRM 4, to provide this functionality. As you can see below, if you go to Data Management –> Bulk Record Deletion, now there is a new button called “New Job”:

image

When you click there, the next form will appear:

image

To select the set of records that you want to delete, you can specify a System View or a Fetch XML.

Behind this, when you press “Created Job”, the main code to be executed is something like:

public static void CreateBulkDeletionJobInCrm(string jobName, DateTime startDateTime, string frequency, int interval, QueryExpression query)
{
BulkDeleteRequest bulkDeleteRequest = new BulkDeleteRequest();
// Set the request properties.
bulkDeleteRequest.JobName = jobName;
bulkDeleteRequest.QuerySet = new QueryBase[] { query };

// Set the start time for the bulk delete.
bulkDeleteRequest.StartDateTime = PropertyHelper.GetUserDateTime(startDateTime);

// Set e-mail activity properties. So far, these properties are not used, but
//they should be initialised
bulkDeleteRequest.SendEmailNotification = false;
bulkDeleteRequest.ToRecipients = new Guid[] { };
bulkDeleteRequest.CCRecipients = new Guid[] { };

// Provide a recurrence pattern so that the job runs once every day.
if(string.IsNullOrEmpty(frequency))
bulkDeleteRequest.RecurrencePattern = string.Empty;
else
bulkDeleteRequest.RecurrencePattern =
String.Format(System.Globalization.CultureInfo.InvariantCulture,
"FREQ={0};INTERVAL={1};", new object[] { frequency, interval });


ServiceFactory.CrmService.Execute(bulkDeleteRequest);

}

The last parameter of this method is a Microsoft.Crm.Sdk.Query.QueryExpression. To get it from a System View or FetchXML, you can use  FetchXmlToQueryExpressionRequest/Response.

Although I would like to provide you  with the whole solution, it’s one of the products of my current company AlfaPeople Ltd, so that you should email me or contact us from our website.

Publicado 06 octubre 09 05:09 por rtebar
Archivado en:

Comentarios

Aún no ha hecho nadie ningún comentario. Escribe alguno y sé el primero :P
No se permiten comentarios de usuarios anónimos

About rtebar

Microsoft Dynamics CRM Developer and Consultant in Alfapeople Ltd (London)

Search

Go

Sindicación