cancel
Showing results for 
Search instead for 
Did you mean: 

Get task forms from RuntimeEventListener implementation

apita
Champ in-the-making
Champ in-the-making

I'm using Alfresco Process Services 1.7

I've implemented a RuntimeEventListener for process lifecycle events and publish them out to a Kafka stream. It's working, but I was unable to fetch task's task_form on TASK_CREATED and/or TASK_COMPLETED events. I figured I'd be able to retrieve the task form with the following code:


EngineServices engineServices = event.getEngineServices();
FormService formService = engineServices.getFormService();
Task task = (Task) ((ActivitiEntityEventImpl) event).getEntity();
Object renderedTaskForm = formService.getRenderedTaskForm(task.getId());
It never returns anything, despite the task having a referenced form. How can I access this information?
1 ACCEPTED ANSWER

cjose
Elite Collaborator
Elite Collaborator

Also, try wiring com.activiti.service.runtime.SubmittedFormService and use submittedFormService .getTaskSubmittedForm(taskId) for task complete events

View answer in original post

11 REPLIES 11

bassam_al-saror
Star Collaborator
Star Collaborator

APS uses a custom form service. If you designed and deployed the process in an APS app you should use AlfrescoTaskFormService.getTaskForm(taskId) instead.

I'm running your code on TASK_CREATED events inside the onEvent method of my RuntimeEventListener implementation. I successfully get the taskId, but I always get a similar error.


Task task = (Task) ((ActivitiEntityEvent) event).getEntity();
String taskId = task.getId(); // returns 192507

FormDefinitionRepresentation taskForm = alfrescoTaskFormService.getTaskForm(taskId);

05:44:43,068 [http-nio-8080-exec-10] WARN org.activiti.engine.delegate.event.impl.ActivitiEventSupport - Exception while executing event-listener, which was ignored
com.activiti.service.exception.NotFoundException: No task with id 192507 exists
at com.activiti.service.runtime.PermissionService.validateReadPermissionOnTask(PermissionService.java:95)
at com.activiti.service.runtime.AlfrescoTaskFormService.getTaskForm(AlfrescoTaskFormService.java:131)
at com.activiti.extension.bean.EagleEventListener.publishEvent(EagleEventListener.java:174)
at com.activiti.extension.bean.EagleEventListener.onEvent(EagleEventListener.java:350)
...

cjose
Elite Collaborator
Elite Collaborator

Also, try wiring com.activiti.service.runtime.SubmittedFormService and use submittedFormService .getTaskSubmittedForm(taskId) for task complete events

apita
Champ in-the-making
Champ in-the-making

Thanks. This works great for TASK_COMPLETED events, but I'm still having trouble fetching task forms on TASK_CREATED events.

bassam_al-saror
Star Collaborator
Star Collaborator

Seems that the event is triggered before the form is created. If assignee is set on the task you can try TASK_ASSIGNED event.

Unfortunately, I get the exact same error on TASK_ASSIGNED events. Any other suggestions?

From the log trace you provided it seems to be a permissions issue. It can't find the history task because it's hasn't been created yet. You can get the form directly using the FormStoreService

formStoreService.getForm(delegateTask.getFormKey());

This worked on TASK_ASSIGNED events. I simply passed in task.getFormKey() to formStoreService.getForm. Thanks!

I'm glad that helped. Btw, that should work for any task event, it will provide the form regardless of the task state.