<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Can not destroy DONE task</title><link>https://answers.axonivy.com/questions/2296/can-not-destroy-done-task</link><description>&lt;p&gt;Hi all&lt;/p&gt;
&lt;p&gt;I'm trying to remove task on server, here is the API&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public static void destroyPendingTasksByProcessContext(String processKey) throws EnvironmentNotAvailableException, PersistencyException, Exception{
        SecurityManagerFactory.getSecurityManager().executeAsSystem(() -&amp;gt; {
            TaskQuery taskQuery = TaskQuery.create()
              .where().customVarCharField5().isEqual(processKey);
            List&amp;lt;ITask&amp;gt; tasks = Ivy.wf().getTaskQueryExecutor().getResults(taskQuery);
            tasks.forEach(destroyTask -&amp;gt; {
                destroyTask.destroy();
            });
            return StringUtils.EMPTY;
        });
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;in the query you can see i use a processkey as a flag to destroy all tasks which are related to my project.
And i got this exception:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Caused by: java.lang.IllegalStateException: State of Task must be one of the following values DELAYED, SUSPENDED, PARKED, RESUMED, UNASSIGNED, FAILED, READY_FOR_JOIN, JOINING, JOIN_FAILED, CREATED, WAITING_FOR_INTERMEDIATE_EVENT but is DONE (The task might have been finished by another user.)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;How can we solve it?
Thanks&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/2296/can-not-destroy-done-task" rel="self"></atom:link><language>en</language><lastBuildDate>Fri, 16 Dec 2016 11:46:13 -0500</lastBuildDate><item><title>Answer by Flavio Sadeghi</title><link>https://answers.axonivy.com/questions/2296/can-not-destroy-done-task/2301</link><description>&lt;p&gt;It’s not possible to destroy a task in state DONE.&lt;/p&gt;
&lt;p&gt;A Task in state DONE or DESTROYED implies that the task has been finished. The state DONE implies a normal ending, the state DESTROYED an abnormal ending (performed by a user / API call). As the state diagram below shows, both are ending states.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Task States" src="http://answers.axonivy.com/upfiles/TaskStateOverview_0wtY7zn.png"&gt;&lt;/p&gt;
&lt;p&gt;Btw, when you try to delete a Task/Case physically from the DB the answer &lt;a href="http://answers.axonivy.com/questions/478/how-to-cleanup-old-cases-tasks"&gt;how-to-cleanup-old-cases-tasks&lt;/a&gt; could help.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Flavio Sadeghi</dc:creator><pubDate>Fri, 16 Dec 2016 11:46:13 -0500</pubDate><guid>https://answers.axonivy.com/questions/2296/can-not-destroy-done-task/2301</guid></item></channel></rss>