<!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;">
Using expression as process duedate value
</h3>
<span style="margin-bottom: 10px;">
created by <a href="http://community.jboss.org/people/Xiaozhangqi">Zhangqi Xiao</a> in <i>jBPM Development</i> - <a href="http://community.jboss.org/message/551657#551657">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p> Hi all,</p><p>   When I configured process dudate as below,</p><pre class="jive-pre"><code class="jive-code jive-xml"><span class="jive-xml-tag"><?xml version="1.0" encoding="UTF-8"?></span>
<span class="jive-xml-tag"><span><process name="TimerRepeat" xmlns="</span><a class="jive-link-external-small" href="http://jbpm.org/4.3/jpdl" target="_blank">http://jbpm.org/4.3/jpdl</a><span>"></span></span>
<span class="jive-xml-tag"><on event="timeout"></span>
  <span class="jive-xml-tag"><timer duedate="#{process_duedate}"/></span>
  <span class="jive-xml-tag"><event-listener /></span>
<span class="jive-xml-tag"></on></span>
<span class="jive-xml-tag"><start g="19,50,48,48"></span>
  <span class="jive-xml-tag"><transition to="guardedWait" /></span>
<span class="jive-xml-tag"></start></span>
<span class="jive-xml-tag"><state name="guardedWait" g="98,46,127,52"></span>
  <span class="jive-xml-tag"><on event="timeout"></span>
   <span class="jive-xml-tag"><timer duedate="#{node_duedate}"/></span>
   <span class="jive-xml-tag"><event-listener /></span>
  <span class="jive-xml-tag"></on></span>
  <span class="jive-xml-tag"><transition name="go on" to="next step" g="-16,-17"/></span>
<span class="jive-xml-tag"></state></span>
<span class="jive-xml-tag"><state name="next step" g="283,46,83,53"/></span>
<span class="jive-xml-tag"></process></span>
</code></pre><p>                                                                                            List 1</p><p>And I started process as:</p><pre class="jive-pre"><code class="jive-code jive-java"> Map<String, String> variables = <font color="navy"><b>new</b></font> HashMap<String, String>();
variables.put(<font color="red">"process_duedate"</font>, <font color="red">"24 business minutes"</font>);
variables.put(<font color="red">"node_duedate"</font>, <font color="red">"12 business minutes"</font>);
ProcessInstance processInstance = executionService.startProcessInstanceByKey(<font color="red">"TimerRepeat"</font>, variables)
</code></pre><p>                                                                                           List 2</p><p>But an exception happend as below:</p><pre class="jive-pre"><code class="jive-code jive-java">javax.script.ScriptException: javax.el.PropertyNotFoundException: Cannot find property process_duedate
at org.jbpm.pvm.internal.script.JuelScriptEngine.evalExpr(JuelScriptEngine.java:180)
at org.jbpm.pvm.internal.script.JuelScriptEngine.eval(JuelScriptEngine.java:64)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:247)
at org.jbpm.pvm.internal.script.ScriptManager.evaluate(ScriptManager.java:126)
at org.jbpm.pvm.internal.script.ScriptManager.evaluate(ScriptManager.java:118)
at org.jbpm.pvm.internal.script.ScriptManager.evaluateExpression(ScriptManager.java:90)
at org.jbpm.pvm.internal.job.TimerImpl.setDueDateDescription(TimerImpl.java:76)
at org.jbpm.pvm.internal.model.ScopeInstanceImpl.createTimer(ScopeInstanceImpl.java:303)
at org.jbpm.pvm.internal.model.ScopeInstanceImpl.initializeTimers(ScopeInstanceImpl.java:323)
at org.jbpm.pvm.internal.model.ExecutionImpl.initializeScopes(ExecutionImpl.java:238)
at org.jbpm.pvm.internal.model.ExecutionImpl.start(ExecutionImpl.java:213)
at org.jbpm.pvm.internal.cmd.StartProcessInstanceCmd.execute(StartProcessInstanceCmd.java:61)
at org.jbpm.pvm.internal.cmd.StartProcessInstanceCmd.execute(StartProcessInstanceCmd.java:37)
at org.jbpm.pvm.internal.svc.DefaultCommandService.execute(DefaultCommandService.java:42)
at org.jbpm.pvm.internal.tx.SpringCommandCallback.doInTransaction(SpringCommandCallback.java:45)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:128)
at org.jbpm.pvm.internal.tx.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:55)
at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.executeInNewEnvironment(EnvironmentInterceptor.java:53)
at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.execute(EnvironmentInterceptor.java:40)
at org.jbpm.pvm.internal.svc.RetryInterceptor.execute(RetryInterceptor.java:55)
at org.jbpm.pvm.internal.svc.ExecutionServiceImpl.startProcessInstanceById(ExecutionServiceImpl.java:58)
</code></pre><p>                                                                                         List 3</p><p>In order to find the reason for this issue, I removed process duedate part from List 1, this resulting is:</p><pre class="jive-pre"><code class="jive-code jive-xml"><span class="jive-xml-tag"><?xml version="1.0" encoding="UTF-8"?></span>
<span class="jive-xml-tag"><span><process name="TimerRepeat" xmlns="</span><a class="jive-link-external-small" href="http://jbpm.org/4.3/jpdl" target="_blank">http://jbpm.org/4.3/jpdl</a><span>"></span></span>
<span class="jive-xml-tag"><start g="19,50,48,48"></span>
  <span class="jive-xml-tag"><transition to="guardedWait" /></span>
<span class="jive-xml-tag"></start></span>
<span class="jive-xml-tag"><state name="guardedWait" g="98,46,127,52"></span>
  <span class="jive-xml-tag"><on event="timeout"></span>
   <span class="jive-xml-tag"><timer duedate="#{node_duedate}"/></span>
   <span class="jive-xml-tag"><event-listener /></span>
  <span class="jive-xml-tag"></on></span>
  <span class="jive-xml-tag"><transition name="go on" to="next step" g="-16,-17"/></span>
<span class="jive-xml-tag"></state></span>
<span class="jive-xml-tag"><state name="next step" g="283,46,83,53"/></span>
<span class="jive-xml-tag"></process></span>
</code></pre><p>                                                                                           List 4</p><p>Then I started process as below :</p><pre class="jive-pre"><code class="jive-code jive-xml"> Map<span class="jive-xml-tag"><String, String></span> variables = new HashMap<span class="jive-xml-tag"><String, String></span>();
variables.put(<span class="jive-xml-quote">node_duedate</span>, <span class="jive-xml-quote">12 business minutes</span>);
ProcessInstance processInstance = executionService.startProcessInstanceByKey(<span class="jive-xml-quote">TimerRepeat</span>, variables)</code></pre><p>                                                                                          List 5</p><p>To my surprised is there was no any error happened and the timer of guardedWait was correctly initialized. why?  After my investigating,I found that</p><p>when ScriptManger caculate expression value, it search from some context scopes,such as excution context,process engine context transactioon, spring context and so on.  but when initialize the process timer duedate,the excution context has not been added to Environment, the source code from class ExecutionImpl as:</p><pre class="jive-pre"><code class="jive-code jive-java"><font color="navy"><b>public</b></font> <font color="navy"><b>void</b></font> start() <font color="navy">{</font>
  <font color="navy"><b>if</b></font> (!STATE_CREATED.equals(state)) <font color="navy">{</font>
   <font color="navy"><b>throw</b></font> <font color="navy"><b>new</b></font> JbpmException(toString() + <font color="red">" is already begun: "</font> + state);
  <font color="navy">}</font>
  this.state = STATE_ACTIVE_ROOT;
  ExecutionImpl scopedExecution = initializeScopes();
  fire(Event.START, getProcessDefinition());
  <font color="navy"><b>if</b></font> (getActivity() != <font color="navy"><b>null</b></font>) <font color="navy">{</font>
   scopedExecution.performAtomicOperation(AtomicOperation.EXECUTE_ACTIVITY);
  <font color="navy">}</font>
<font color="navy">}</font>
</code></pre><p>                                                                                          List 6</p><p>This " initializeScopes()" method is excuted before "scopedExecution.performAtomicOperation(AtomicOperation.EXECUTE_ACTIVITY);"  if enter accitiy it is ok, but when start process,it is wrong. so I changed method "initializeProcessInstance" from class "ExecutionImpl" as below:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java"><font color="navy"><b>public</b></font> <font color="navy"><b>void</b></font> initializeProcessInstance(ProcessDefinitionImpl processDefinition, String key) <font color="navy">{</font>
  setProcessDefinition(processDefinition);
  setActivity((ActivityImpl) processDefinition.getInitial());
  this.processInstance = <font color="navy"><b>this</b></font>;
  this.state = STATE_CREATED;
  this.key = key;
  save();
  composeIds();
 
  <font color="darkgreen">//Added by me to add excution context to environment</font>
  ExecutionContext originalExecutionContext = <font color="navy"><b>null</b></font>;
  ExecutionContext executionContext = <font color="navy"><b>null</b></font>;
  EnvironmentImpl environment = EnvironmentImpl.getCurrent();
  <font color="navy"><b>if</b></font> (environment != <font color="navy"><b>null</b></font>) <font color="navy">{</font>
   originalExecutionContext = (ExecutionContext) environment.getContext(Context.CONTEXTNAME_EXECUTION);
   <font color="navy"><b>if</b></font> ((originalExecutionContext != <font color="navy"><b>null</b></font>) && (originalExecutionContext.getExecution() == <font color="navy"><b>this</b></font>)) <font color="navy">{</font>
    originalExecutionContext = <font color="navy"><b>null</b></font>;
   <font color="navy">}</font> <font color="navy"><b>else</b></font> <font color="navy">{</font>
    executionContext = <font color="navy"><b>new</b></font> ExecutionContext(<font color="navy"><b>this</b></font>);
    environment.setContext(executionContext);
   <font color="navy">}</font>
  <font color="darkgreen">//ended add</font>
 
  <font color="navy">}</font>
  HistoryEvent.fire(<font color="navy"><b>new</b></font> ProcessInstanceCreate(), <font color="navy"><b>this</b></font>);
<font color="navy">}</font>
 
</code></pre><p>                                                                                          List 7<br/> By doing so,when I configured process duedate as list1 and start process as list 2.it was ok! </p><p> I konw the way  I used is not the best one! but can any one tell me the best way or is it a bug need to be fixed?</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/551657#551657">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>