<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Get active process Instances with associated tasks in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/get-active-process-instances-with-associated-tasks/m-p/38913#M16374</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a requirement to get the list of all active instances along with the tasks under every instance. I did the below but unable to retrieve the tasks under the instance. Appreciate any pointers.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//Get the list of all active process instances&lt;/P&gt;&lt;PRE style="color: #a9b7c6; background-color: #2b2b2b; font-size: 9.0pt;"&gt;List&amp;lt;ProcessInstance&amp;gt; processInstances = &lt;SPAN style="color: #9876aa;"&gt;runtimeService&lt;/SPAN&gt;.createProcessInstanceQuery().active().list()&lt;SPAN style="color: #cc7832;"&gt;;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//Iterate through the instances and cast it to ExecutionEntity to get more info.&lt;/P&gt;&lt;PRE style="color: #a9b7c6; background-color: #2b2b2b; font-size: 9.0pt;"&gt;&lt;SPAN style="color: #cc7832;"&gt;for&lt;/SPAN&gt;(ProcessInstance processInstance : data) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ExecutionEntity entity = (ExecutionEntity)processInstance&lt;SPAN style="color: #cc7832;"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(TaskEntity task : entity.getTasks()) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;...&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;}&lt;/PRE&gt;&lt;P&gt;While performing entity.getTasks(), it throws a NPE.&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;java.lang.NullPointerException: null&lt;BR /&gt; at org.activiti.engine.impl.persistence.entity.ExecutionEntity.ensureTasksInitialized(ExecutionEntity.java:1391)&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Looks like Context.getCommandContext() inside the ensureTasksInitialized method is returning null.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do&amp;nbsp;I get around this problem? Isn't the correct way of retrieving the tasks under an instance?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 22 May 2017 16:13:26 GMT</pubDate>
    <dc:creator>sam_a</dc:creator>
    <dc:date>2017-05-22T16:13:26Z</dc:date>
    <item>
      <title>Get active process Instances with associated tasks</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/get-active-process-instances-with-associated-tasks/m-p/38913#M16374</link>
      <description>I have a requirement to get the list of all active instances along with the tasks under every instance. I did the below but unable to retrieve the tasks under the instance. Appreciate any pointers.//Get the list of all active process instancesList&amp;lt;ProcessInstance&amp;gt; processInstances = runtimeSer</description>
      <pubDate>Mon, 22 May 2017 16:13:26 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/get-active-process-instances-with-associated-tasks/m-p/38913#M16374</guid>
      <dc:creator>sam_a</dc:creator>
      <dc:date>2017-05-22T16:13:26Z</dc:date>
    </item>
    <item>
      <title>Re: Get active process Instances with associated tasks</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/get-active-process-instances-with-associated-tasks/m-p/38914#M16375</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your execution entity is just a shell and will not be populated with all of the properties you need.&lt;/P&gt;&lt;P&gt;It will include the processInstanceId which will be enough for you to issue a task query based on the ProcessInstanceId:&lt;BR /&gt;&lt;BR /&gt;List&amp;lt;task&amp;gt; myTasks = taskService.createTaskQuery.processInstanceId(entity.getId()).list();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You will then have a list of Task entities.&lt;/P&gt;&lt;P&gt;Just be aware, each of these queries ultimately results in a SQL call to the database so it could be potentially costly in high volume. There may be a better way of getting the same data if the instances share a common business key or process variables that you can do a direct Task query on and group by process Instance.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps,&lt;BR /&gt;Greg&lt;/P&gt;&lt;P&gt;&lt;A href="https://migration33.stage.lithium.com/t5/tag/bp3/tg-p"&gt;&lt;/A&gt;‌&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 May 2017 19:54:47 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/get-active-process-instances-with-associated-tasks/m-p/38914#M16375</guid>
      <dc:creator>gdharley</dc:creator>
      <dc:date>2017-05-22T19:54:47Z</dc:date>
    </item>
    <item>
      <title>Re: Get active process Instances with associated tasks</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/get-active-process-instances-with-associated-tasks/m-p/38915#M16376</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Greg. I see that there is method&amp;nbsp;&lt;SPAN style="color: #727174; background-color: #ffffff;"&gt;processInstanceIdIn(List&amp;lt;String&amp;gt; processInstanceIds) which takes in list of processInstance ids. Is it possible to use the mentioned method to get the list of tasks across many instances and group them by processInstance?&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 May 2017 03:32:54 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/get-active-process-instances-with-associated-tasks/m-p/38915#M16376</guid>
      <dc:creator>sam_a</dc:creator>
      <dc:date>2017-05-23T03:32:54Z</dc:date>
    </item>
  </channel>
</rss>

