<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Problems with Local Task Service
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/roxy1987">Shobhit Tyagi</a> in <i>jBPM</i> - <a href="https://community.jboss.org/message/809857#809857">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Guys,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I have a process with 2 tasks. I am using local task service. The process starts fine and completion of 1st task is also clean. but the 2nd task is not assigned. neither it is listed in the database. What could be the reason?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Following is my code for initiate process and complete task.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Initiate :</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code jive-java">StatefulKnowledgeSession ksession;
&#160; <font color="navy"><b>long</b></font> processInstanceId = -1;
&#160; <font color="navy"><b>try</b></font>
&#160; <font color="navy">{</font>
&#160;&#160; ksession = BpmRepositoryConfig.createSession(processName);
&#160;&#160; KnowledgeRuntimeLogger logger1 = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession, <font color="red">"testlog"</font>, 1000);
&#160;&#160; LocalHTWorkItemHandler handler = <font color="navy"><b>new</b></font> LocalHTWorkItemHandler(ksession);
&#160;&#160; org.jbpm.task.service.TaskService service = BpmRepositoryConfig.getService();
&#160;&#160; TaskService taService = BpmRepositoryConfig.getTaskService(ksession, service);
&#160;&#160; handler.setClient(taService);
&#160;&#160; ksession.getWorkItemManager().registerWorkItemHandler(<font color="red">"Human Task"</font>, handler);
&#160;&#160;&#160;&#160;&#160; JPAWorkingMemoryDbLogger logger2 = <font color="navy"><b>new</b></font> JPAWorkingMemoryDbLogger(ksession);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; ProcessInstance prcInstance = ksession.startProcess(processDefId, mapParameters);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; processInstanceId = prcInstance.getId();
&#160; <font color="navy">}</font>
&#160; <font color="navy"><b>catch</b></font> (Exception e)
&#160; <font color="navy">{</font>
&#160;&#160; e.printStackTrace();
&#160; <font color="navy">}</font>
&#160;
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Complete :</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code jive-java">StatefulKnowledgeSession ksession = BpmRepositoryConfig.createSession(processName);
&#160; org.jbpm.task.service.TaskService tservice = BpmRepositoryConfig.getService(); 
&#160; TaskService taskService = BpmRepositoryConfig.getTaskService(ksession,tservice);
&#160; <font color="navy"><b>try</b></font>
&#160; <font color="navy">{</font>
&#160;&#160; <font color="navy"><b>for</b></font>(<font color="navy"><b>long</b></font> task : taskId)
&#160;&#160; <font color="navy">{</font>
&#160;&#160;&#160; taskService.start(task, userId); 
&#160;&#160;&#160; taskService.complete(task, userId, <font color="navy"><b>null</b></font>);
&#160;&#160; <font color="navy">}</font>
&#160; <font color="navy">}</font>
&#160; <font color="navy"><b>catch</b></font> (Exception e)
&#160; <font color="navy">{</font>
&#160;&#160; e.printStackTrace();
&#160; <font color="navy">}</font>
&#160;
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Other methods : </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code jive-java"> <font color="navy"><b>public</b></font> <font color="navy"><b>static</b></font> org.jbpm.task.service.TaskService getService()
 <font color="navy">{</font>
&#160; EntityManagerFactory emf = Persistence.createEntityManagerFactory(<font color="red">"org.jbpm.task"</font>);
&#160; org.jbpm.task.service.TaskService tservice = <font color="navy"><b>new</b></font> org.jbpm.task.service.TaskService(emf, SystemEventListenerFactory.getSystemEventListener());
&#160; TaskServiceSession taskSession = tservice.createSession();&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160; taskSession.addUser(<font color="navy"><b>new</b></font> User(<font color="red">"Administrator"</font>));
&#160;&#160;&#160;&#160;&#160;&#160;&#160; taskSession.addUser(<font color="navy"><b>new</b></font> User(<font color="red">"krisv"</font>)); 
&#160;&#160;&#160;&#160;&#160;&#160;&#160; taskSession.addUser(<font color="navy"><b>new</b></font> User(<font color="red">"john"</font>));
&#160;&#160;&#160;&#160;&#160;&#160;&#160; taskSession.addUser(<font color="navy"><b>new</b></font> User(<font color="red">"mary"</font>));
&#160; <font color="navy"><b>return</b></font> tservice;
 <font color="navy">}</font>
&#160;
&#160;
 <font color="navy"><b>public</b></font> static&#160; TaskService getTaskService(StatefulKnowledgeSession ksession,org.jbpm.task.service.TaskService taskService)
 <font color="navy">{</font>&#160;&#160;&#160;&#160;&#160;&#160; 
&#160; TaskService client = <font color="navy"><b>new</b></font> LocalTaskService(taskService);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; LocalHTWorkItemHandler localHTWorkItemHandler = <font color="navy"><b>new</b></font> LocalHTWorkItemHandler(client, ksession);
&#160;&#160;&#160;&#160; ksession.getWorkItemManager().registerWorkItemHandler(<font color="red">"Human Task"</font>, localHTWorkItemHandler);
&#160;&#160;&#160;&#160; <font color="navy"><b>return</b></font> client;&#160; 
&#160;&#160;&#160; <font color="navy">}</font>
&#160;
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Thanks.</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/809857#809857">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in jBPM at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>