Query history variable instance

Hi,

We have variable stored in ACT_HI_VARINST. we need to query the history based on our variable say example “calculator” and we need to apply pagination and date filter such as fromDate and toDate. Second, when there is no filter criteria such as date and pagination we need to fetch all the history for our variable, this data might be huge so we need this record within 30 seconds.

how do we achieve this?

@Adithyan you can refer this rest api docs for querying historic process variables with various filter options & including sorting.

https://docs.camunda.org/manual/7.9/reference/rest/history/variable-instance/post-variable-instance-query/

Optionally, you can add Query params like firstResult & maxResults for pagination.

Hi Thanks for replying.

i would like to fetch the history with date filter like fromDate and toDate.
how do i do that?

  1. If you’re refering task started date and task completed date, then first query for historic task instances Get Tasks (Historic) (POST) | docs.camunda.org and collect the list of processInstanceIds based on your filter criteria. When you query of task instances you have to set filter variables in the attribute processVariables.

    Below are list of date related fields in Historic task instance.

taskDueDate Restrict to tasks that are due on the given date. By default*, the date must have the format yyyy-MM-dd’T’HH:mm:ss.SSSZ, e.g., 2013-01-23T14:42:45.000+0200.
taskDueDateBefore Restrict to tasks that are due before the given date. By default*, the date must have the format yyyy-MM-dd’T’HH:mm:ss.SSSZ, e.g., 2013-01-23T14:42:45.000+0200.
taskDueDateAfter Restrict to tasks that are due after the given date. By default*, the date must have the format yyyy-MM-dd’T’HH:mm:ss.SSSZ, e.g., 2013-01-23T14:42:45.000+0200.
taskFollowUpDate Restrict to tasks that have a followUp date on the given date. By default*, the date must have the format yyyy-MM-dd’T’HH:mm:ss.SSSZ, e.g., 2013-01-23T14:42:45.000+0200.
taskFollowUpDateBefore Restrict to tasks that have a followUp date before the given date. By default*, the date must have the format yyyy-MM-dd’T’HH:mm:ss.SSSZ, e.g., 2013-01-23T14:42:45.000+0200.
taskFollowUpDateAfter Restrict to tasks that have a followUp date after the given date. By default*, the date must have the format yyyy-MM-dd’T’HH:mm:ss.SSSZ, e.g., 2013-01-23T14:42:45.000+0200.
startedBefore Restrict to tasks that were started before the given date. By default*, the date must have the format yyyy-MM-dd’T’HH:mm:ss.SSSZ, e.g., 2013-01-23T14:42:45.000+0200.
startedAfter Restrict to tasks that were started after the given date. By default*, the date must have the format yyyy-MM-dd’T’HH:mm:ss.SSSZ, e.g., 2013-01-23T14:42:45.000+0200.
finishedBefore Restrict to tasks that were finished before the given date. By default*, the date must have the format yyyy-MM-dd’T’HH:mm:ss.SSSZ, e.g., 2013-01-23T14:42:45.000+0200.
finishedAfter Restrict to tasks that were finished after the given date. By default*, the date must have the format yyyy-MM-dd’T’HH:mm:ss.SSSZ, e.g., 2013-01-23T14:42:45.000+0200.
  1. Now you have list of process instance ids to query further variable instances. https://docs.camunda.org/manual/7.9/reference/rest/history/variable-instance/post-variable-instance-query/

    Input the list of process instance ids collected from Point 1.

1 Like

Thanks for replying.

great, even we have followed the same approach but the problem since we need to query taks instance for processInstanceId and then query the history based on processInstanceId is taking time if the record is more.
our scenario:- we have got 80K record when we query first we will get 80K processInstanceId and passing 80K processinstance to get 80K history is taking more time.

is there any way to get this result within 30seconds?

Thanks,
Adithyan

@Adithyan you can apply pagination logic for historic task instance only and get list of process instance ids and pass it to variable instance query. Pagination will take less than a second. Dont apply pagination for variable instance query since you have applied pagination for task instance

Hi,

we have two requirement below

  1. one with pagination and date - this is absolutely working fine
  2. get all history without pagination and then write it into excel - this is taking more time if the record count is more.

Any solution for #2 ?

If you query for entire data it will utilize maximum memory and sometimes you’ll face timeout exception too. So its better to try something like streaming logic which will pull chunks of data in every api call and keep writing to the excel.

1 Like

thank you so much, i will try to take a look.