The best solution for this problem would probably be to remove the documents in a system lane activity as the very last step of the process instance. There are at least 3 ways to do that:
- Loop over each entry in tw.system.currentProcessInstance.documents and delete via the TWDocument.deleteAllVersions() API call.
- Use the CMIS operations in the 'Content Integration Task' from a service flow to first retrieve all of the documents using the 'Search' method and looking for documents matching the current process instance ID, then loop over each returned document and issue the 'Delete document' call from another 'Content Integration Task'.
- Using the REST API, obtain the process instance details via /rest/bpm/wle/v1/process/[processInstanceId] - the response contains data.documents and this can be looped over and the REST API call to delete an instance document can be called via a POST /rest/bpm/wle/v1/process/[processInstanceId]?action=deleteDocument&docId=[documentId]
If adding a step to the process cannot be done, then some sort of polling (i.e. time-based UCA) mechanism could be used to check for completed or terminated instances on a scheduled basis, then loop over any documents associated with the instance and delete them. Querying all completed or terminated instances using TWSearch or the REST API could get expensive over time depending on the volume of process instances, so it is advisable to also track whether or not a process instance's documents have been cleaned up. If a system of record is available, tracking whether or not the process instance's documents have been cleaned up would be pretty straightforward. Without an external way to track this, there might be a way to query completed or terminated instances whose last modified date is within the past 24 hours, for example, and only process those. That would at least limit the instances being processed in a single scheduled cleanup job to just those completed within the past day. Increasing the interval to 48 hours or even 7 days might be a little safer in case jobs don't run due to scheduled maintenance or some other unexpected issue.
Hope that helps you get pointed in the right direction! Thanks -Don
------------------------------
Don Williams
------------------------------
Original Message:
Sent: Sun May 16, 2021 07:41 AM
From: Eduardo Izquierdo Lázaro
Subject: Is it possible to delete Documents attached to process instances?
When using embedded BPM document store, is there some administrative script or API to cleanup documents attached to instances?
The requirement is to delete documents attached to old completed instances for regulatory compliance, but without deleting the instances itself, that are still needed for performance dashboards.
Any good practice around is welcome.
I guess that right answer is to use an external ECM to leverage full document lifecycle management independently of the process instances lifecycle, but in this case the client is using internal BAW doc store.
------------------------------
Eduardo Izquierdo Lázaro
Automation Architect
DECIDE
------------------------------