<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MSCRM Blogger &#187; system jobs</title>
	<atom:link href="http://mscrmblogger.com/tag/system-jobs/feed/" rel="self" type="application/rss+xml" />
	<link>http://mscrmblogger.com</link>
	<description>Achieving it all with Microsoft Dynamics CRM™</description>
	<lastBuildDate>Thu, 10 May 2012 20:24:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Bulk Delete System Jobs</title>
		<link>http://mscrmblogger.com/2009/02/12/bulk-delete-system-jobs/</link>
		<comments>http://mscrmblogger.com/2009/02/12/bulk-delete-system-jobs/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 05:59:37 +0000</pubDate>
		<dc:creator>Carlton Colter</dc:creator>
				<category><![CDATA[API-SDK]]></category>
		<category><![CDATA[Extensions]]></category>
		<category><![CDATA[General API Usage]]></category>
		<category><![CDATA[bulk delete]]></category>
		<category><![CDATA[crm4]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[system jobs]]></category>
		<category><![CDATA[workflow]]></category>

		<guid isPermaLink="false">http://mscrmblogger.com/?p=34</guid>
		<description><![CDATA[CRM 4.0has an endless amounts of system job logs.  We perform automatic actions on a lot of entities, but we don't need the log of those automatic actions beyond the end of that working day if it was Canceled or Completed Successfully.  Now we can setup a custom bulk deletion job that won't keep those successful entries.]]></description>
			<content:encoded><![CDATA[<p>CRM 4.0has an endless amounts of system job logs.  We perform automatic actions on a lot of entities, but we don&#8217;t need the log of those automatic actions beyond the end of that working day if it was Canceled or Completed Successfully.  Unfortunately, setting up a bulk delete task for system job logs is not as easy as setting up other bulk delete jobs.  I modified the code from <a href="http://blogs.msdn.com/crm/archive/2008/11/13/leveraging-bulk-delete-jobs-to-manage-system-job-log-records.aspx" target="_new">Sean McNellis&#8217; blog entry on leveraging bulk delete jobs to manage system job log records</a>.</p>
<p><b>Below is my code (which is a modified version of the runBulkDelete from the <a href="http://code.msdn.microsoft.com/crmbulkdelete/Release/ProjectReleases.aspx?ReleaseId=1795" target="_new">Microsoft Bulk Delete Sample</a> for deleting successfully completed or canceled jobs:</b></p>
<pre name="code" class="csharp">
        static void runBulkDeleteAsyncoperations(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("statuscode",
                        ConditionOperator.Equal,
                        new object[]{(int)AsyncOperationStatus.Canceled,(int)AsyncOperationStatus.Succeeded});
            Guid[] emptyRecipients = new Guid[0];
            BulkDeleteRequest request = new BulkDeleteRequest();
            request.JobName = "Bulk Delete Successfully Completed or Canceled Asyncoperations and Workflow Logs";
            request.QuerySet = new QueryBase[] { expression.Query };
            request.ToRecipients = emptyRecipients;
            request.CCRecipients = emptyRecipients;
            request.SendEmailNotification = false;
            request.RecurrencePattern = "FREQ=DAILY;INTERVAL=1;";
            request.StartDateTime = CrmDateTime.Now;

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

            Console.WriteLine("Bulk delete job with id: {0} has been created", response.JobId);
        }
</pre>
<p>Their code examples use a month time span, and if you are trying to delete everything older than 3 days, then you need to build an executable and schedule it to run daily to create the bulk deletion job.  You will also need the following filter to be added to the code, and set the RecurrencePattern equal to string.empty.</p>
<pre name="code" class="csharp">
expression.Criteria.Conditions.AddCondition("completedon", ConditionOperator.OnOrBefore, DateTime.Now.AddDays(-3).ToString("yyyy-MM-dd"));
</pre>
<p>If by some chance you are curious about creating Bulk Delete Jobs in general, <a href="http://blogs.msdn.com/crm/archive/2008/04/24/bulk-record-deletion-in-microsoft-crm-online.aspx" target="_new">check out msdn blog entry</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://mscrmblogger.com/2009/02/12/bulk-delete-system-jobs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

