cancel
Showing results for 
Search instead for 
Did you mean: 

Saving comment in process without user task

ivan_activiti
Champ in-the-making
Champ in-the-making
I have a process consisting of a start event, a couple of service tasks, and a mail task. In the start even, there are some form fields users fill out. There is also a comment field which is not part of the form. The comment field is rendered after the form and users have an option to add a comment. On the back end I call the following code to start the process:


ProcessInstance pi = runtimeService.startProcessInstanceByKey(processDefinitionKey, variableMap);

then, I would like to save the comment, by using:


taskService.addComment(null, pi.getId(), commentText);

The line above will only work if there is a user task present in the process, but in this particular process there is no user tasks. So, I am getting
org.activiti.engine.ActivitiObjectNotFoundException: execution doesn't exist
exception.

I realize one of the options would be to write some custom method that would save my comment to the
ACT_HI_COMMENT
table. But is there something out-of-the-box in Activiti that would allow me to save a comment in this use case? I am using version 5.16.3

Thanks,
–Ivan
2 REPLIES 2

trademak
Star Contributor
Star Contributor
Hi Ivan,

This is the correct way to add a comment to a process instance. However, we currently only support adding comments to running process instances. Is your process instance already completed when invoking the addComment method?

Best regards,

ivan_activiti
Champ in-the-making
Champ in-the-making
I call the <code>taskService.addComment(null, pi.getId(), commentText);</code> in my code right after the process is started. I assume since there is no user task in my process, it completes before a comment can be added. If I add a user task after the start event, the comment is added successfully.