Tuesday, February 10, 2015

Stuck Dynamics CRM ImportJob importing a Solution

Did you know that you can view the progress of your import by using Advanced Find to query Import Jobs?  If you ever "lost touch" with the progress bar window, this can be very useful.  I have a saved view that displays the imports from the last 7 days in descending order.

Unfortunately, jobs can get stuck during import and prevent you from importing your solution again.  In that situation, you need to manually delete the stuck job.  Fortunately this is super easy with the Advanced Find you created above.  There is a special Delete button on this view.

You can also do it programmatically with the early-bound classes and a Linq query in the Service Context:

var xrm = new XrmServiceContext("Xrm");
var deadJobs = xrm.ImportJobSet.Where(x => x.CompletedOn.Equals(null));

foreach (var job in deadJobs)
{
    Console.WriteLine("Deleting Job Created On: " +job.CreatedOn);
    xrm.Delete(ImportJob.EntityLogicalName, job.Id);
    xrm.SaveChanges();
}

No comments: