Delete process variables and history after process instance completed

Hello

Can anyone recommend the best approach to delete process instance variables and associated history after the instance completes? My use case requires that the variable data exists only when the process instance is running. Once it completes I need to delete the variable data and all history. This doesn’t apply to all process definitions only a select few, so enabling this via configuration would be the best option.

Any help on this would be appreciated.

Thanks

Hi @aminmc,

have a look into this snippet: https://github.com/camunda-consulting/code/tree/master/snippets/change-history-output. It supresses that some variables are written in the history at all.

Hope this helps, Ingo

Thanks @Ingo_Richtsmeier. This helps a lot. once the process completes all its data is moved to the history tables so this should prevent the variables existing in the history.

Thanks

The History cleanup (1) is also an option.

(1): https://docs.camunda.org/manual/7.9/user-guide/process-engine/history/#history-cleanup

Thanks @Yana. How do I trigger this clean up for as specific process definition after the completion of the instance? What’s the post completion hook I need to integrate in order to make sure the data is deleted without causing a transaction issue?

I can see I can use the HistoryService to delete the history data for a specific process instance but just not clear when is a good place to call this method, can it be used in an ExecutionListener? Don’t think I can as that’s part of the existing transaction which could have a strange effect?

Hi @aminmc,

You need to configure historyTimeToLive in the process definition (1) and then you can either trigger the history cleanup manually (2) or configure it to run all the time/specific times (3).

Setting historyTimeToLive=0 will mean the historic process instances (and their data) will be ready for delete after they finished.

(1): https://docs.camunda.org/manual/7.9/user-guide/process-engine/history/#history-time-to-live
(2): https://docs.camunda.org/manual/7.9/user-guide/process-engine/history/#manual-run
(3): https://docs.camunda.org/manual/7.9/user-guide/process-engine/history/#periodic-run

Best regards,
Yana

excellent thanks @Yana!

Cheers
Amin

Hi Ingo_Richtsmeier,

could you please share the same active link again. The link which you shared throwing 404.

Thanks & Regards,
Vinit Kumar

Hi @Vinit_Kumar,

as the option is now part of the product, you can find an example here: https://github.com/camunda/camunda-bpm-examples/tree/master/process-engine-plugin/custom-history-level.

Hope this helps, Ingo

Thanks @Ingo_Richtsmeier this help me to solve my issue.

Thanks & Regards,
Vinit Kumar