[rules-users] Using ForEach variables in split constraints

sam.squire at paretopartners.com sam.squire at paretopartners.com
Thu Sep 23 10:06:08 EDT 2010


Hello there,

I wanted to refer to a variable in a split constraint in a ForEach node. 
What is the correct way to nest a split node in a ForEach node and refer 
to the variable of the collection?

I have tried the following:

a)  Start process and insert process into session, providing the map 
containing the collectionExpression. Using:

<import name="org.drools.runtime.process.WorkflowProcessInstance"/> 

processIntance: WorkflowProcessInstance()
$item: MyObject: (this == (processInstance.getVariable("item")))

this doesn't seem to grab the variable like I expected it to.

How can I assign processInstance.getVariable("item") itself to a variable? 
(I imagine this would work if this did)


b) Set the variable on the global process from the current context

kcontext.getProcessInstance().setVariable("item", 
kcontext.getVariable("item")


I know this is not the right answer.

c) Insert the item in an action at the beginning of the loop. Retract it 
at the end. I then match against the item of type MyObject at the 
beginning.

// in action:
insert(item)
// in constraint
$item: MyObject()
// after action
retract(item)

This requires looping in Java to start the processes individually and 
setting the variable explicitly each time.

This seems a bit of a roundabout way of doing it, what is *the* correct 
method?

Thanks,

This message may contain confidential and privileged information and is intended solely for the use of the named addressee. Access, copying or re-use of the e-mail or any information contained therein by any other person is not authorised. If you are not the intended recipient please notify us immediately by returning the e-mail to the originator and then immediately delete this message. Although we attempt to sweep e-mail and attachments for viruses, we do not guarantee that either are virus-free and accept no liability for any damage sustained as a result of viruses.

Please refer to http://www.bnymellon.com/disclaimer/piml.html for certain disclosures.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20100923/8c060040/attachment.html 


More information about the rules-users mailing list