Getting WorkflowInstance of a given DelegateTask in Java

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2014 12:13 PM
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
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
Labels:
- Labels:
-
Archive
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2014 01:18 PM
ScriptTaskListener implements TaskListener
–>public void notify(DelegateTask delegateTask)
—->DelegateTask extends VariableScope
public interface VariableScope –> Object getVariable(String variableName)
Therefore, delegateTask.getVariable("initiator") will return the Task Initiator.
I expect it is an ActivitiScriptNode, so you may have to do a getNodeRef call on the returned object.
HTH, let me know if I am being a little too terse ;-).
regards,
Mark
–>public void notify(DelegateTask delegateTask)
—->DelegateTask extends VariableScope
public interface VariableScope –> Object getVariable(String variableName)
Therefore, delegateTask.getVariable("initiator") will return the Task Initiator.
I expect it is an ActivitiScriptNode, so you may have to do a getNodeRef call on the returned object.
HTH, let me know if I am being a little too terse ;-).
regards,
Mark

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2014 06:49 PM
Thanks so much mstang. That was plenty of information to get started in the right direction. This is the code snippet for anyone else.
ActivitiScriptNode actScriptNode = (ActivitiScriptNode) task
.getVariable("initiator");
NodeRef nodeRef = actScriptNode.getNodeRef();
Map<QName, Serializable> props = getServiceRegistry()
.getNodeService().getProperties(nodeRef);
Set<QName> keys = props.keySet();
for (QName qname : keys) {
if (qname.getLocalName().equalsIgnoreCase("email")) {
String email = (String) props.get(qname);
}
}
ActivitiScriptNode actScriptNode = (ActivitiScriptNode) task
.getVariable("initiator");
NodeRef nodeRef = actScriptNode.getNodeRef();
Map<QName, Serializable> props = getServiceRegistry()
.getNodeService().getProperties(nodeRef);
Set<QName> keys = props.keySet();
for (QName qname : keys) {
if (qname.getLocalName().equalsIgnoreCase("email")) {
String email = (String) props.get(qname);
}
}
