Why and when to perform this task
Process instances are only automatically deleted when they complete if this is specified in the process template from which the process instances are derived. To delete all finished process instances:Steps for this task
QueryResultSet result = process.query("DISTINCT PROCESS_INSTANCE.PIID", "PROCESS_INSTANCE.STATE = PROCESS_INSTANCE.STATE.STATE_FINISHED", null, null, null);
PIID piid; while (result.next() ) { piid = (PIID) result.getOID(1); process.delete(piid); }