AnsweredAssumed Answered

Getting WorkflowInstance of a given DelegateTask in Java

Question asked by cafeguy on Aug 15, 2014
Latest reply on Aug 15, 2014 by cafeguy
Hi Forum,
  I have an Activiti task that invokes a custom Java.  In the custom Java I need to send an email to the workflow initiator with an update.  I'm a little stuck on how to get the WorkflowInstance given the current task so I could get the initiator.  My code snippet is below.

public class MailTask extends ScriptTaskListener {


ServiceRegistry servReg = getServiceRegistry();
String taskId = "activiti$" + task.getId();
WorkflowTask wfTask = servReg.getWorkflowService().getTaskById(taskId);

// how do I get the workflow wfTask belongs to from here? 
WorkflowService has method getActiveWorkflows(), but it'll give me all the active workflow instances.
// there is a method getWorkflowById(workflowId), but I'm stuck of how to get the workflowId.
}

Thank you forum for your help.

Environment:
Alfresco community 4.2a
Activiti Engine 5.7

Outcomes