AnsweredAssumed Answered

How to get the ID of the process instance in the controller?

Question asked by Aleksey Bykov on Mar 12, 2017
Latest reply on Mar 13, 2017 by Aleksey Bykov

My environment:


Alfresco Share v5.2.d (r134641-b15, Aikau, Spring Surf 5.2.d, Spring WebScripts 6.13, Freemarker 2.3.20-alfresco-patched, Rhino 1.7R4-alfresco-patched, Yui 2.9.0-alfresco-20141223)


Alfresco Community v5.2.0 (r134428-b13) schema 10005


When I start the workflow, I can assign executors - the list of users who will participate in the business process.
I need to get a list of all those users and display this list in the reviewTask screen.


To display this data I have the custom FreeMarker template. From this template I'll call my Web Script.


To interact with the repository through REST I use the Web Script Framework MVC - the controller that executes the logic of receiving the list of users and FreeMarker template for the JSON response.


I've been offered the great idea, how it can be done. But I faced with some problem.


Let's say, I launched multiple instances of the business process. In the Workflow Console I can see the following:


id: activiti$1801 , desc: DESCRIPTION_1 , start date: Sun Mar 12 19:19:09 GST 2017 , def: activiti$activitiParallelReview v1
id: activiti$2005 , desc: DESCRIPTION_2 , start date: Sun Mar 12 20:11:57 GST 2017 , def: activiti$activitiParallelReview v1
id: activiti$2138 , desc: DESCRIPTION_3 , start date: Sun Mar 12 20:12:55 GST 2017 , def: activiti$activitiParallelReview v1


Thus I have three IDs:




These IDs are available for me only in the Workflow Console.


How can I get these identifiers in the controller?


Can I, for example, write a class that will be called by Activiti? Let's say,


public class SomeListener implements TaskListener {
     public void notify(DelegateTask task) {
          String taskId = task.getId();


Then attach it to the complete event of the some task and pass ID to the controller.

Is this the right way?..


I would be very grateful for the information. Thanks to all.




I wrote a class that implements the ExecutionListener interface. Then added it as a listener on the transition from mswf:submitParallelReviewTask to mswf:activitiReviewTask.


All the properties that I need, I can get here (Thank to Gagravarr for his answer):


public class PropertiesReceiver implements ExecutionListener {
     private static final long serialVersionUID = 1L;
     private static Log logger = LogFactory.getLog(PropertiesReceiver.class);
     public void notify(DelegateExecution delegateExecution) throws Exception {
          // TODO Auto-generated method stub
          String processInstanceId = delegateExecution.getProcessInstanceId();
          logger.debug("processInstanceId == " + processInstanceId);
          ActivitiScriptNodeList assignees =
                    (ActivitiScriptNodeList) delegateExecution.getVariable("bpm_assignees");
          for (ActivitiScriptNode personNode : assignees) {
               String username = (String) personNode.getProperties().get("cm:userName");
               logger.debug("username == " + username);




2017-03-13 11:03:12,244  DEBUG [mswf.bpm.PropertiesReceiver] [http-apr-8080-exec-3] processInstanceId == 26205
2017-03-13 11:03:12,248  DEBUG [mswf.bpm.PropertiesReceiver] [http-apr-8080-exec-3] username == first
2017-03-13 11:03:12,250  DEBUG [mswf.bpm.PropertiesReceiver] [http-apr-8080-exec-3] username == second


But this is a separate project, packaged in an AMP file.