History related questions

i have following questions on history.
My requirement is to store all process instances even after they are completed/resolved and that they should be searchable.

I see that once I resolve/complete the process instance, it gets removed from runtime table and if I use following REST API, I can not retrieve it.
http://localhost:8086/rest/engine/default/process-instance?processInstanceIds={id}

Also, I see that the resolved process id is available in ACT_HI_PROCINST table. but the variables are no more present for the case.
How can I get resolved/completed process instances and all its variable data?

Also, just to mention, I am using Camunda Community Edition. (in case if there is any limitation with Community edition)

@Ashish_Pingale, Variables are stored in ACT_HI_VARINST table, and check the below page for querying variables.

REST API: https://docs.camunda.org/manual/7.13/reference/rest/history/variable-instance/


The detailed log will be available in ACT_HI_DETAIL table.

Note:

  • History data for variables won’t be available if configured History level is NONE or ACTIVITY
  • For variables history, the history level should be either AUDIT or FULL

https://docs.camunda.org/manual/latest/user-guide/process-engine/history/#choose-a-history-level

2 Likes

Hi, yes I got my question partially answered. Thanks a lot. However I have following questions ->

  1. Is there an API to return all variable instances for a process instance?

Second question I have is related to audit history
Is there a way to insert my own audit history for a process instance. eg. I want to add to audit history that integration call succeeded. Either through a delegate or a rest API?

Hi @Ashish_Pingale,

you can intercept the history events like in a custom history level: https://docs.camunda.org/manual/7.13/user-guide/process-engine/history/#implement-a-custom-history-level.

In the end of the section an example is linked.

Hope this helps, Ingo

Hi @Ashish_Pingale,

Refer this: Get Variable Instances (POST) | docs.camunda.org

POST /history/variable-instance

and query with below payload:

{
  "processInstanceId": "someProcessInstanceId",
  "processDefinitionKey": "someProcessDefinitionKey"
}

This will fetch the all variables for the given processInstanceId and processDefinitionKey.

History events are generated by process engine, rest api not available to persist the history variables.

Best approach could be, once integration call succeeded, you can set the status in a process/task variable using Java Delegates or Listeners like below:

execution.setVariable("integrationStatus", "Success");

So this variable also persisted in history tables and queried back later using above rest api.

Hello,
This suggestion was very helpful. However, if I add multiple updates to a variable instance, the above api /history/variable-instance only returns the latest updated value.
How do I get all updates to a particular variable from the history? Can you please let me know.

The detail API might be what you are looking for:

https://docs.camunda.org/manual/latest/reference/rest/history/detail/

For this data history-level full is necessary…

Thank you that works