cancel
Showing results for 
Search instead for 
Did you mean: 

Starting a process instance synchronously

gant
Champ in-the-making
Champ in-the-making
Hi,

I think it's not possible to run a process instance synchronously, I mean, to get the "output" process variables after execution?

I'd like to do something like:
Map<String,Object> outcome = myRuntimeService.startInstance("myBackgroundProcess", vars);

Where 'myBackgroundProcess' is a composition of service tasks.

What would be the best (a good) way, to achieve this?

Thanks,
michael
4 REPLIES 4

trademak
Star Contributor
Star Contributor
Hi,

Activiti runs synchronously if you have only automatic tasks in your process.
So you can do something similar to what you want, only you need 2 lines of code.
With the process instance ID you get back from the start method, you can retrieve all the variables via the HistoricService.

Best regards,

gant
Champ in-the-making
Champ in-the-making
Hi,

Thank you for your quick answer.

I'm not familiar with historyService. I can get HistoricProcessInstance or HistoricDetail, but how can I get the variables from there?

Kind regards,
michael

trademak
Star Contributor
Star Contributor
Hi,

You do something like this:

List<HistoricDetail> historicVariableUpdateList = historyService.createHistoricDetailQuery().variableUpdates().list();
for (HistoricDetail historicDetail : historicVariableUpdateList) {
  HistoricVariableUpdate historicVariableUpdate = (HistoricVariableUpdate) historicDetail;
  System.out.println("historic variable update, revision " + historicVariableUpdate.getRevision() +
    ", variable type name " + historicVariableUpdate.getVariableTypeName() +
    ", variable name " + historicVariableUpdate.getVariableName() +
    ", Variable value '" + historicVariableUpdate.getValue()+"'");
}

This way you get all process variable updates if you set the historyLevel of the process engine to full.
You can order it so you get the latest updates first.

Best regards,

gant
Champ in-the-making
Champ in-the-making
Hi,

I have a process with two Script Tasks and tried to got the variables using the historyService. Following is the result:

Name: y * Value: 2 * Revision: 0 * Time: 1311931591000
Name: x * Value: 4 * Revision: 0 * Time: 1311931591000
Name: x * Value: 6.0 * Revision: 0 * Time: 1311931591000
Name: y * Value: 12.0 * Revision: 0 * Time: 1311931591000
Name: x * Value: 36.0 * Revision: 0 * Time: 1311931591000
Name: y * Value: -24.0 * Revision: 0 * Time: 1311931591000

the values are correct, 2 and 4 are the values in the input variables, line 3&4 are the correct values after first scripts task, lines 5&6 after the second script task. But why is the revision always 0? and the timestamp always the same?

Thanks!