<!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="http://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;">
    [jbpm5.1]Can get the current nodeId,correctly??
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/leo87601">leo li</a> in <i>jBPM Development</i> - <a href="http://community.jboss.org/message/638682#638682">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Dear all,</p><p>We want to get the current node name after completed a task.But it is not working correctly some time. </p><p>we found the error happen here. </p><p>long nodeId =<span style="color: #ff0000;"> wfInstance.getNodeInstances().iterator().next().getNodeId();</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="color: #ff0000;">BTW, Before we setted the persistence, this issue does not happen.</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The data seem had problem too,&#160; we found that the PROCESSINSTANCEINFO's lastmodificationdate(12:44:36) is the same as the pending node's log time, but the workflow had been run into Qualified at 12:44:43. </p><p>We can not see the processinstancebytearray, so not sure the processintanceinfo had been updated correctly or not? </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>select * from nodeinstancelog where processinstanceid =134 order by id desc;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><table cellpadding="0" cellspacing="0"><tbody><tr><th style=";"><a class="jive-link-external-small" href="http://localhost:8082/query.do?jsessionid=eba938cf1dbf38d4a410125bbe377788#">ID<span class="sortArrow">&#160; </span></a></th><th style=";"><a class="jive-link-external-small" href="http://localhost:8082/query.do?jsessionid=eba938cf1dbf38d4a410125bbe377788#">TYPE<span class="sortArrow">&#160; </span></a></th><th style=";"><a class="jive-link-external-small" href="http://localhost:8082/query.do?jsessionid=eba938cf1dbf38d4a410125bbe377788#">NODEINSTANCEID<span class="sortArrow">&#160; </span></a></th><th style=";"><a class="jive-link-external-small" href="http://localhost:8082/query.do?jsessionid=eba938cf1dbf38d4a410125bbe377788#">NODEID<span class="sortArrow">&#160; </span></a></th><th style=";"><a class="jive-link-external-small" href="http://localhost:8082/query.do?jsessionid=eba938cf1dbf38d4a410125bbe377788#">PROCESSINSTANCEID<span class="sortArrow">&#160; </span></a></th><th style=";"><a class="jive-link-external-small" href="http://localhost:8082/query.do?jsessionid=eba938cf1dbf38d4a410125bbe377788#">PROCESSID<span class="sortArrow">&#160; </span></a></th><th style=";"><a class="jive-link-external-small" href="http://localhost:8082/query.do?jsessionid=eba938cf1dbf38d4a410125bbe377788#">LOG_DATE<span class="sortArrow">&#160; </span></a></th><th style=";"><a class="jive-link-external-small" href="http://localhost:8082/query.do?jsessionid=eba938cf1dbf38d4a410125bbe377788#">NODENAME<span class="sortArrow">&#160; </span></a></th></tr><tr><td style=";">683</td><td style=";">0</td><td style=";">5</td><td style=";">9</td><td style=";">134</td><td style=";">LeadProcess</td><td style=";">2011-11-28 12:44:43.048</td><td style=";">Qualified</td></tr><tr><td style=";">682</td><td style=";">1</td><td style=";">4</td><td style=";">8</td><td style=";">134</td><td style=";">LeadProcess</td><td style=";">2011-11-28 12:44:43.048</td><td style=";">Gateway</td></tr><tr><td style=";">681</td><td style=";">0</td><td style=";">4</td><td style=";">8</td><td style=";">134</td><td style=";">LeadProcess</td><td style=";">2011-11-28 12:44:43.048</td><td style=";">Gateway</td></tr><tr><td style=";">680</td><td style=";">1</td><td style=";">3</td><td style=";">5</td><td style=";">134</td><td style=";">LeadProcess</td><td style=";">2011-11-28 12:44:43.033</td><td style=";">Pending</td></tr><tr><td style=";">679</td><td style=";">0</td><td style=";">3</td><td style=";">5</td><td style=";">134</td><td style=";">LeadProcess</td><td style=";">2011-11-28 12:44:36.36</td><td style=";">Pending</td></tr></tbody></table><p><span style="font-size: 12px;"><br/><br/></span></p><p>SELECT * FROM PROCESSINSTANCEINFO where iNSTANCEID =134;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><table cellpadding="0" cellspacing="0"><tbody><tr><th style=";"><a class="jive-link-external-small" href="http://localhost:8082/query.do?jsessionid=eba938cf1dbf38d4a410125bbe377788#">INSTANCEID<span class="sortArrow">&#160; </span></a></th><th style=";"><a class="jive-link-external-small" href="http://localhost:8082/query.do?jsessionid=eba938cf1dbf38d4a410125bbe377788#">LASTMODIFICATIONDATE<span class="sortArrow">&#160; </span></a></th><th style=";"><a class="jive-link-external-small" href="http://localhost:8082/query.do?jsessionid=eba938cf1dbf38d4a410125bbe377788#">LASTREADDATE<span class="sortArrow">&#160; </span></a></th><th style=";"><a class="jive-link-external-small" href="http://localhost:8082/query.do?jsessionid=eba938cf1dbf38d4a410125bbe377788#">PROCESSID<span class="sortArrow">&#160; </span></a></th><th style=";"><a class="jive-link-external-small" href="http://localhost:8082/query.do?jsessionid=eba938cf1dbf38d4a410125bbe377788#">PROCESSINSTANCEBYTEARRAY<span class="sortArrow">&#160; </span></a></th><th style=";"><a class="jive-link-external-small" href="http://localhost:8082/query.do?jsessionid=eba938cf1dbf38d4a410125bbe377788#">STARTDATE<span class="sortArrow">&#160; </span></a></th><th style=";"><a class="jive-link-external-small" href="http://localhost:8082/query.do?jsessionid=eba938cf1dbf38d4a410125bbe377788#">STATE<span class="sortArrow">&#160; </span></a></th><th style=";"><a class="jive-link-external-small" href="http://localhost:8082/query.do?jsessionid=eba938cf1dbf38d4a410125bbe377788#">OPTLOCK<span class="sortArrow">&#160; </span></a></th></tr><tr><td style=";">134</td><td style=";">2011-11-28 12:44:36.376</td><td style=";">2011-11-28 12:57:39.437</td><td style=";">LeadProcess</td><td style=";">aced00057765000852756c65466c6f770000000000000086000b4c65616450726f6365737300000001000000000000000400000000001200000000000000030000000000000005001b00000000000000fd00000000000100000000000000020006616374696f6e0000000074000750656e64696e67770c0006757365724964000000007400056b72697376</td></tr></tbody></table><p><span style="font-size: 12px;"><br/></span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Environment : Jboss 5.1,&#160; h2 database, windows 2003. we are using the default setting of jbpm-5.1.0.Final-installer-full.zip</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Here is our code of complete task. </p><p>public ProcessInstanceBO completeUserTask(long instanceId, String toState){</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>ProcessInstance instance = ksession.getProcessInstance(instanceId);&#160; // init process by instanceid</p><p>WorkflowProcessInstance wfInstance = ((WorkflowProcessInstance)instance);</p><p>// get currently Node instances</p><p>Iterator&lt;NodeInstance&gt; iterator = wfInstance.getNodeInstances().iterator();</p><p>NodeInstance nodeInstance = iterator.next();&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>// compelte workitem.</p><p>final long workItemId = workItemNodeInstance.getWorkItemId();</p><p>final Map&lt;String, Object&gt; results = new HashMap&lt;String, Object&gt;();</p><p>results.put(this.ACTION, toState);</p><p>ksession.getWorkItemManager().completeWorkItem(workItemId, results);</p><p>ksession.getWorkItemManager().abortWorkItem(workItemId);</p><p>// retrieve the process instance again.</p><p>instance = ksession.getProcessInstance(instanceId);</p><p>WorkflowProcessInstance wfInstance = (WorkflowProcessInstance) instance;</p><p><span style="color: #3366ff;">//retrieve the current node again. we expect that , here is the next step's nodeid, but it doesn't work correctly every time. some time it still in the last stage</span>.</p><p>long nodeId = wfInstance.getNodeInstances().iterator().next().getNodeId();</p><p>logger.debug("Process current node id: " + nodeId );</p><p>WorkflowProcess wfProcess = (WorkflowProcess) readKnowledgeBase().getProcess(wfInstance.getProcessId());</p><p><span style="color: #3366ff;">//We cannot get the correct Node name because.</span></p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Node node = wfProcess.getNode(nodeId);</p><p>....</p><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>We are confusing on this issue, please help. Thanks a lots.</p></div>

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


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

</div>

</body>
</html>