<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: How to cleanup old Cases / Tasks?</title><link>https://answers.axonivy.com/questions/478/how-to-cleanup-old-cases-tasks</link><description>&lt;p&gt;Currently there is no functionality in XIVY Server Administrator App(s) to clean up old workflow data from XIVY system DB. But it can happen that all the old data is no more used and slows down the data base. How can I get rid of them?&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/478/how-to-cleanup-old-cases-tasks" rel="self"></atom:link><language>en</language><lastBuildDate>Fri, 01 Apr 2016 11:34:06 -0400</lastBuildDate><item><title>Answer by Reguel Wermelinger</title><link>https://answers.axonivy.com/questions/478/how-to-cleanup-old-cases-tasks/1707</link><description>&lt;p&gt;&lt;strong&gt;Delete Tasks and Cases in Xpert.ivy 3.9&lt;/strong&gt;
&lt;br&gt;&lt;br&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;via Workflow Admin UI&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Workflow Administrators can delete tasks and cases within a date range over the administration UI.
&lt;img alt="alt text" src="http://answers.axonivy.com/upfiles/clear39tasksAndCases.png"&gt;&lt;/p&gt;
&lt;p&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;via SystemDB&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Sample query to select taskIds which will be destroyed. Rewrite it to a DELETE statement to really remove the data.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;SELECT d.TaskId
  FROM IWA_TaskData as d
  JOIN IWA_Task as t ON d.TaskId = t.TaskId
  WHERE t.State IN (6,7) /** delete only done and destroyed tasks **/
  AND d.TaskDataKind = 1; /** delete only start data, keep current data **/
  AND t.DoneTimestamp = XYZ /** limit the date: only delete data older than 3 years or similar **/
&lt;/code&gt;&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Fri, 01 Apr 2016 11:34:06 -0400</pubDate><guid>https://answers.axonivy.com/questions/478/how-to-cleanup-old-cases-tasks/1707</guid></item><item><title>Answer by Tamas KIS</title><link>https://answers.axonivy.com/questions/478/how-to-cleanup-old-cases-tasks/479</link><description>&lt;p&gt;There are two ways to do this, one directly in the system DB and one with an API call.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Delete via Public API&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;you can build a process/App around the Public API: &lt;a href="http://developer.axonivy.com/doc/latest/publicApi/ch/ivyteam/ivy/workflow/IWorkflowContext.html#deleteCompletedCase-ch.ivyteam.ivy.workflow.ICase-"&gt;void deleteCompletedCase(ICase completedCase) throws PersistencyException&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;A simple script which deletes old cases could look as follows:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public class HistoricCaseDeleter {
    public static void doIt()
    {
        CaseQuery oldCasesQuery = CaseQuery.create().where()
            .state().isEqual(CaseState.DESTROYED).or()
            .state().isEqual(CaseState.DONE).or()
            .state().isEqual(CaseState.ZOMBIE)
            .and()
            .startTimestamp().isLowerThan(new java.util.Date(2010, 0, 1));

        for(ICase oldCase : Ivy.wf().getCaseQueryExecutor().getResults(oldCasesQuery))
        {
            Ivy.wf().deleteCompletedCase(oldCase);
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Delete directly in System DB&lt;/strong&gt; &lt;/p&gt;
&lt;p&gt;You may clean up cases and tasks in Done (2) and Destroyed (3) state as follows:&lt;br&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Stop Axon.ivy server v4.x or later&lt;/li&gt;
&lt;li&gt;Backup your DB (of course)&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Execute to know how many cases you are about to remove: &lt;br&gt;
    &lt;em&gt;SELECT COUNT(&lt;/em&gt;)
          FROM [YourIvySystemDb].[dbo].[IWA_Case]
          WHERE State = 2 OR State = 3*&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Execute to remove them: &lt;br&gt;
    &lt;em&gt;DELETE FROM [YourIvySystemDb].[dbo].[IWA_Case] WHERE State = 2 OR State = 3&lt;/em&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;You may shrink your DB to save disk space (e.g. MSSQL manager tool can do that)&lt;/li&gt;
&lt;li&gt;Start Axon.ivy server again&lt;/li&gt;
&lt;/ol&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Tamas KIS</dc:creator><pubDate>Thu, 26 Sep 2013 02:56:36 -0400</pubDate><guid>https://answers.axonivy.com/questions/478/how-to-cleanup-old-cases-tasks/479</guid></item></channel></rss>