title: Camunda : get active tasks
body: <p>How can i get a list of active tasks in the code i use in Camunda ?</p>
  
  <p>I already look at this answer "<a href="https://stackoverflow.com/questions/23359503/how-to-query-the-position-of-a-process-instance">How to query the position of a process instance?</a>" but i can't understand what is "processInstanceId" and where i am supposed to get it to make this method works.</p>
  
  <p>Here's the code i'm currently trying : </p>
  
  <pre><code>package org.camunda.bpm;
  
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  import org.camunda.bpm.engine.ProcessEngine;
  import org.camunda.bpm.engine.RepositoryService;
  import org.camunda.bpm.engine.RuntimeService;
  import org.camunda.bpm.engine.runtime.ProcessInstance;
  import org.camunda.bpm.model.bpmn.BpmnModelInstance;
  import org.camunda.bpm.model.xml.instance.ModelElementInstance;
  
  public class AllActiveActivities {
  
  public Map&lt;String, String&gt; getAllActiveActivities(String processInstanceId) {
  // get engine services
  ProcessEngine processEngine = BpmPlatform.getDefaultProcessEngine()
  RuntimeService runtimeService = processEngine.getRuntimeService();
  RepositoryService repositoryService = processEngine.getRepositoryService();
  
  // get the process instance
  ProcessInstance processInstance =
      runtimeService.createProcessInstanceQuery()
          .processInstanceId(processInstanceId)
          .singleResult();
  
  HashMap&lt;String, String&gt; activityNameByActivityId = new HashMap&lt;String, String&gt;();
  
  // get all active activities of the process instance
  List&lt;String&gt; activeActivityIds =
      runtimeService.getActiveActivityIds(processInstance.getId());
  
  // get bpmn model of the process instance
  BpmnModelInstance bpmnModelInstance =
      repositoryService.getBpmnModelInstance(processInstance.getProcessDefinitionId());
  
  for (String activeActivityId : activeActivityIds) {
    // get the speaking name of each activity in the diagram
    ModelElementInstance modelElementById =
        bpmnModelInstance.getModelElementById(activeActivityId);
    String activityName = modelElementById.getAttributeValue("name");
  
    activityNameByActivityId.put(activeActivityId, activityName);
  }
  
  // map contains now all active activities
  return activityNameByActivityId;
  }
  
  }
  </code></pre>
  
  <p>Thanks in advance for your help.</p>