cancel
Showing results for 
Search instead for 
Did you mean: 

Get process instances history for a specific object

pedrog1
Champ in-the-making
Champ in-the-making
Hi everyone

In my app I'm building workflows and I want to get the history of the workflows triggered for a specific object.

When the workflows are executing, is easy to retrieve the workflows for that entity/object, the API gives everything is needed, but when it ends and it's needed to be accessed via History API I can't find a way to retrieve those objects.

I will try to explain how I do it.

This is how I start a workflow

Map<String, Object> variables = new HashMap<String, Object>();

variables.put("my_object_class", myObject.getClass().getName());
variables.put("my_object_id", myObject.getId());

runtimeService.startProcessInstanceByKey(processDefinitionKey, variables);

This is how I retrieve ongoing workflows for my object

private List<ProcessInstance> returnProcessInstances(MyObject myObject) {
   Map<String, Object> variables = new HashMap<String, Object>();

   variables.put("my_object_class", myObject.getClass().getName());
   variables.put("my_object_id", myObject.getId());

   for(Map.Entry<String, Object> variable : variables.entrySet()) {
      query.variableValueEquals(variable.getKey(), variable.getValue());
   }
   return query.list();
}

I have the history in full mode, so everything is persisted in the DB.
How can I access the BD and retrieve the process instances with the variables provided? Should I do it in a different way?

Thanks
10 REPLIES 10

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
Where is your query defined and what is it?

pedrog1
Champ in-the-making
Champ in-the-making
Where is your query defined and what is it?

Thanks for your quick reply.
Sorry, it get lost in the copy/paste Smiley Wink

It looks something like this:


private List<ProcessInstance> returnOngoingProcessInstances(MyObject myObject) {
   Map<String, Object> variables = new HashMap<String, Object>();

   variables.put("my_object_class", myObject.getClass().getName());
   variables.put("my_object_id", myObject.getId());

   ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery();
  
   for(Map.Entry<String, Object> variable : variables.entrySet()) {
      query.variableValueEquals(variable.getKey(), variable.getValue());
   }
   return query.list();
}

My point is, i can retrieve easily the process instances with specific variables with the runtime API, but when they are finished and go the the history tables, I don't know how to do it. I can't find anything in the HistoryService that allows me to retrieve the process instances that have some variables (they are in the db, I have the history log in full mode).

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
Uhhhmmmm did you have a look at chapter 11 from the documentation?

pedrog1
Champ in-the-making
Champ in-the-making
Uhhhmmmm did you have a look at chapter 11 from the documentation?

I did. But I can't find a way to get all the process instances (completed) for my object when what connects my object to the process instances are the variables (as you can see in my first post).


   HistoryProcessInstanceQuery processInstanceQuery = historyService.createHistoricProcessInstanceQuery();
I had tried different ways to use the HistoryProcessInstanceQuery with variables, without success. When the process instance was executing it was easy (first post).

I will try to exemplify with what I have in my db.
ACT_HI_PROCINST (three completed processes)

ID_  PROC_INST_ID_  PROC_DEF_ID_
5   5   teste:1:4
6   6   teste:1:4
7   7   teste:1:4

ACT_HI_DETAIL (six variables, two for each process instance)

ID_  TYPE_  PROC_INST_ID_  NAME_  LONG_  TEXT_
10  VariableUpdate  5  obj_class  NULL  com.myapp.order
8  VariableUpdate  5  obj_id  9876  9876
14  VariableUpdate  6  obj_class  NULL  com.myapp.order
12  VariableUpdate  6  obj_id  12345  12345
16  VariableUpdate  7  obj_class  NULL  com.myapp.order
14  VariableUpdate  7  obj_id  12345  12345

How can I use the HistoryService to load the process instances of the order 12345?

It is probably that I'm not connecting the process instances with my object in the right way… it will be nice if someone point me in the right direction Smiley Wink

Thanks Smiley Happy

rogerofyan
Champ in-the-making
Champ in-the-making
I got the same requirements as you, but I use another approach.
I store the process instance id as a property in my object, and query it with HistoricProcessInstance.processInstanceId()

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
why don't you use the businesskey concept of activiti? or do like rogerofyan did store things the othe way around

pedrog1
Champ in-the-making
Champ in-the-making
why don't you use the businesskey concept of activiti? or do like rogerofyan did store things the othe way around

Thank you for your replies  Smiley Wink

I've tried to use the businesskey concept, it would work perfectly if it allowed more than one record with the same businesskey per process definition. My objects can have multiple workflows of the same process definition; also, rogerofyan approach will not work for me because of this.

I've just found what would solve my problem, my problem is exactly the same.
http://jira.codehaus.org/browse/ACT-1230
http://forums.activiti.org/en/viewtopic.php?f=6&t=3011
http://forums.activiti.org/en/viewtopic.php?f=6&t=2922

Thanks for your replies. I will check the source code and try to remove the unique constrain in the business key…

sfeinstein
Champ in-the-making
Champ in-the-making
I would love some additional guidance on this thread.  I think the author has laid it out exactly:
  • Business keys are broken for use cases where duplicates are OK from a business point of view

  • You can't query historic process instances for variables, even if you have enabled full historical detail
As far as I can tell this makes it near impossible to do meaningful things with historical data through the APIs.

franck102
Champ in-the-making
Champ in-the-making
Resurrecting this thread as I am facing the exact same problem… any chance the unique constraint could get dropped?