Get task forms from RuntimeEventListener implementation

cancel
Showing results for 
Search instead for 
Did you mean: 
apita
Member II

Get task forms from RuntimeEventListener implementation

Jump to solution

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 Solution

Accepted Solutions
cjose
Senior Member II

Re: Get task forms from RuntimeEventListener implementation

Jump to solution

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

View solution in original post

11 Replies
bassam_al-saror
Alfresco Employee

Re: Get task forms from RuntimeEventListener implementation

Jump to solution

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

cjose
Senior Member II

Re: Get task forms from RuntimeEventListener implementation

Jump to solution

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

apita
Member II

Re: Get task forms from RuntimeEventListener implementation

Jump to solution

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)
...

apita
Member II

Re: Get task forms from RuntimeEventListener implementation

Jump to solution

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

bassam_al-saror
Alfresco Employee

Re: Get task forms from RuntimeEventListener implementation

Jump to solution

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

apita
Member II

Re: Get task forms from RuntimeEventListener implementation

Jump to solution

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

bassam_al-saror
Alfresco Employee

Re: Get task forms from RuntimeEventListener implementation

Jump to solution

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());

apita
Member II

Re: Get task forms from RuntimeEventListener implementation

Jump to solution

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

bassam_al-saror
Alfresco Employee

Re: Get task forms from RuntimeEventListener implementation

Jump to solution

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