<br><span class="gI"></span>According to the documentation:<br><br><blockquote style="margin:0pt 0pt 0pt 6.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">&quot;Rule constraints do not have direct access to variables defined inside the process. <br>

It is however possible to refer to the current process instance inside a rule constraint, <br>by adding the process instance to the Working Memory and matching for the process instance in your rule constraint. <br>We have added special logic to make sure that a variable processInstance of type WorkflowProcessInstance <br>

will only match to the current process instance and not to other process instances in the Working Memory. <br>Note that you are however responsible yourself to insert the process instance into the session and, <br>possibly, to update it, for example, using Java code or an on-entry or on-exit or explicit action in your process. <br>

The following example of a rule constraint will search for a person with the same name as the value stored in the variable &quot;name&quot; of the process:&quot;<br></blockquote><br><br>This however does not seem to be true.<br>

<br>The first rule is to receive a stream of objects of type MyObject.<br>This rule starts an associated process.<br><br>The second rule will be called by the process (from bpmn).<br><br>Within the process there a task that invokes an an asynchronous service, ie,<br>

an implementation of WorkItemHandler that contains a Thread that will set call <br>manager.completeWorkItem(workItemId,results);<br>when 30s have passed).<br><br>With this setup we can observe what happens when 2 MyObject instances come into the first rule separated by a short period of time (say 5 seconds).<br>

<br>When the first object comes in a process is created and started (with process id=1)<br>The process passes from the start node to the callMyTask node, which invokes the slow WorkItemHandler references by MyTask <br>(which we have previously registered into session.getWorkItemManager() ). <br>

Because the WorkItemHandler has a thread that waits 30s before completing the work item, it just sits there doing nothing (so far everything is ok)<br>and allows the engine to process other events.<br><br>5 seconds later we insert another MyObject into the stream.<br>

The first rule gets fired and created another process (with process id=2).<br>The process passes from the start node to the callMyTask node, which invoke our slow service.<br><br>We have thus two processes running in parallel.<br>

<br>When the first callMyTask node completes, the next node completeTask is invoked.<br><br>The rule &quot;process complete&quot; is matched as it belongs to the rule flow group &quot;Complete task group&quot;.<br><br>At this point we observe that the rule is matched twice spitting out:<br>

<br>    processInstance.id 2<br>    processInstance.id 1<br>.<br>So the rule has matched both process instances that are in working memory and not just the one (with process id 1) <br>that called the &quot;process complete&quot; rule.<br>

<br><br><br>The rule file<br>-------------<br><br>rule &quot;New case&quot;<br>    when    <br>        $myobject : MyObject(processed==false) from entry-point &quot;myobject stream&quot;        <br>    then<br>        ProcessInstance processInstance=kcontext.getKnowledgeRuntime().createProcessInstance(&quot;com.mycompany.process.MyProcess&quot;, parameters);<br>

        insert(processInstance);<br>        kcontext.getKnowledgeRuntime().startProcessInstance(processInstance.getId());<br>        modify ($myobject){<br>            setProcessed(true)<br>        }<br>    end<br>    <br>

rule &quot;process complete&quot;<br>    ruleflow-group &quot;Complete task group&quot;<br>    no-loop true<br>    when<br>        $processInstance: WorkflowProcessInstance()<br>    then<br>        System.out.println(&quot;processInstance.id &quot; + $processInstance.getId());<br>

    end<br>    <br><br>The BPMN xml<br>------------<br>    <br>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; <br>&lt;definitions id=&quot;Definition&quot;<br>             targetNamespace=&quot;<a href="http://www.jboss.org/drools">http://www.jboss.org/drools</a>&quot;<br>

             typeLanguage=&quot;<a href="http://www.java.com/javaTypes">http://www.java.com/javaTypes</a>&quot;<br>             expressionLanguage=&quot;<a href="http://www.mvel.org/2.0">http://www.mvel.org/2.0</a>&quot;<br>

             xmlns=&quot;<a href="http://www.omg.org/spec/BPMN/20100524/MODEL">http://www.omg.org/spec/BPMN/20100524/MODEL</a>&quot;<br>             xmlns:xsi=&quot;<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>&quot;<br>

             xsi:schemaLocation=&quot;<a href="http://www.omg.org/spec/BPMN/20100524/MODEL">http://www.omg.org/spec/BPMN/20100524/MODEL</a> BPMN20.xsd&quot;<br>             xmlns:g=&quot;<a href="http://www.jboss.org/drools/flow/gpd">http://www.jboss.org/drools/flow/gpd</a>&quot;<br>

             xmlns:bpmndi=&quot;<a href="http://www.omg.org/spec/BPMN/20100524/DI">http://www.omg.org/spec/BPMN/20100524/DI</a>&quot;<br>             xmlns:dc=&quot;<a href="http://www.omg.org/spec/DD/20100524/DC">http://www.omg.org/spec/DD/20100524/DC</a>&quot;<br>

             xmlns:di=&quot;<a href="http://www.omg.org/spec/DD/20100524/DI">http://www.omg.org/spec/DD/20100524/DI</a>&quot;<br>             xmlns:tns=&quot;<a href="http://www.jboss.org/drools">http://www.jboss.org/drools</a>&quot;&gt;<br>

<br>    &lt;process processType=&quot;Private&quot; isExecutable=&quot;true&quot; id=&quot;com.mycompany.process.MyProcess&quot; name=&quot;my process&quot; &gt;<br><br>        &lt;!-- process variables --&gt;<br>        <br>

        &lt;!-- nodes --&gt;<br>        &lt;startEvent id=&quot;start&quot; name=&quot;StartProcess&quot; /&gt;<br>        <br>        &lt;task id=&quot;callMyTask&quot; name=&quot;call my task&quot; tns:taskName=&quot;MyTask&quot; &gt;<br>

            &lt;ioSpecification&gt;<br>            &lt;/ioSpecification&gt;<br>        &lt;/task&gt;<br>    <br>    <br>        &lt;businessRuleTask id=&quot;completeTask&quot; name=&quot;Complete slow task&quot; g:ruleFlowGroup=&quot;Complete task group&quot; &gt;<br>

        &lt;/businessRuleTask&gt;<br>    <br>        &lt;endEvent id=&quot;end&quot; name=&quot;EndProcess&quot; /&gt;<br><br>        &lt;!-- connections --&gt;<br>        &lt;sequenceFlow id=&quot;start-callMyTask&quot; sourceRef=&quot;start&quot; targetRef=&quot;callMyTask&quot; /&gt;<br>

        &lt;sequenceFlow id=&quot;callMyTask-completeTask&quot; sourceRef=&quot;callMyTask&quot; targetRef=&quot;completeTask&quot; /&gt;<br>        &lt;sequenceFlow id=&quot;completeTask-end&quot; sourceRef=&quot;completeTask&quot; targetRef=&quot;end&quot; /&gt;<br>

    &lt;/process&gt;<br>&lt;/definitions&gt;<br><br><br>What&#39;s wrong with this?  Isn&#39;t WorkflowProcessInstance() supposed to be attached to the calling ProcessInstance?  Is there another way of getting the group of rules fire only for the processinstance that called it?<br>

<br><br clear="all">Greets,<br>