AnsweredAssumed Answered

Get process instances history for a specific object

Question asked by pedrog1 on May 28, 2012
Latest reply on Jan 21, 2014 by jbarrez
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

Outcomes