Delete all completed tasks and workflows in the repository

cancel
Showing results for 
Search instead for 
Did you mean: 

Delete all completed tasks and workflows in the repository

menczingerm
Active Member
1 1 751

Description:

My goal was to delete all active and completed tasks and workflows in ACS and here is some information what i found out untill i could reach my goal. 

Conclusions

  • Workflow Console "delete all worfklows imeanit" command only delete active tasks and workflows
  • Trying to undeploy and redeploy a workflow definistion name with workflow conolse will delete completed workflows related to that workflow definition but it will not remove the completed tasks - undeploying a workflow definition will cause you a problem - completed task without deployed definition  (link
    Exception (with status template): 01030136 Failed to execute script 'Javascript Console Script': null
    org.springframework.extensions.webscripts.WebScriptException: 01030006 Wrapped Exception (with status template): 01030136 Failed to execute script 'Javascript Console Script': null
        at org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:1139)
  • With Alfresco RestApi you are not able to manage completed tasks/workflows only active tasks/workflows
  • I also found out someone managed to delete completed task/workflows with deleting records directly in the DB, how ever i did not investigate this deeply.

Solution:

So the solution what worked for me is to write a custom javascript code what i could run with javascript console to remove completed task and workflows in the repository.

Here is the script:

var ctxt = Packages.org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext();
var service = ctxt.getBean('WorkflowService', Packages.org.alfresco.service.cmr.workflow.WorkflowService);
var activitiProcessEngine = ctxt.getBean('activitiProcessEngine', Packages.org.activiti.engine.impl.ProcessEngineImpl);

var activitiUtil = new org.alfresco.repo.workflow.activiti.ActivitiUtil(activitiProcessEngine, false);
var historyService = activitiUtil.getHistoryService();


var completedWorkflows = service.getCompletedWorkflows();

while(completedWorkflows.size() > 0){
    var wfToDelete = completedWorkflows.remove(0);
    var id = wfToDelete.getId();

    historyService.deleteHistoricProcessInstance(id.substr(9));
    logger.log("WF deleted: " + id);

    completedWorkflows = service.getCompletedWorkflows();

}

The script tested with ACS 5.2 CE AND ACS 6.2 CE

I would like to thank my colleagues at BroadBit Hungary and @angelborroy  @openpj for their help

Ps.: If you have any comment or suggestion please dont hasitate to post it.

1 Comment