cancel
Showing results for 
Search instead for 
Did you mean: 

Issue when trying to get process Variable

frank41
Champ in-the-making
Champ in-the-making
Hi all Activiti users,
I've some troubles when recovering one process variable set within a Service task.
As I understand from the API, I need the executionId in order to get a variable:

runtimeService.getVariable(execId,"myvar");

However the following code give me a NPE:

ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process1",params);

Execution exec1 = runtimeService
              .createExecutionQuery()         
              .processInstanceId(processInstance.getId())
              .singleResult();

System.out.println(exec1); // Null!

Do you have any hint to solve this issue ???
Thanks
Frank
3 REPLIES 3

frank41
Champ in-the-making
Champ in-the-making
Found the culprit- depending on the value of the process variable- the process can move to the End Node where there's obviously no more an Execution.

I beg your pardon, is it possible to query for the last value of a process variable even if the process completed ?
Thanks

trademak
Star Contributor
Star Contributor
Sure you can, you can use the HistoryService. That's where all process data, completed and running is stored.

Best regards,

frank41
Champ in-the-making
Champ in-the-making
Thanks!