How to access TaskService from JavaDelegate

Hi. I’m new to Flowable and writing a JavaDelegate that will create a file (Excel using Apache POI) and attach it to the current Task. Assuming I need to use TaskService#createAttachment, how do I get a handle to TaskService from DelegateExecution ?

Thanks.

You can use org.flowable.engine.impl.util.getProcessEngineConfiguration.getTaskService()

Thanks.

I can get the service. But not sure how to get the TaskId. Trying this:

    taskService.createAttachment(type, taskId, execution.getProcessInstanceId(), name, description, inputStream);

I see that as my task is executing (running in a FlowableRule test), the ACT_RU_TASK table is not populated. How can I add an attachment if the task is not found in that table?

So perhaps I was thinking about this the wrong way. Used a TaskListener on a UserTask’s ‘complete’ event instead. This works:

public void notify(DelegateTask delegateTask) {

    TaskService taskService = Context.getProcessEngineConfiguration().getTaskService();

    taskService.createAttachment(type, delegateTask.getId(), delegateTask.getProcessInstanceId(),
            name, description, inputStream);
}