-
1. Re: Invoking a business rule from a process
ahmedza Dec 30, 2013 2:05 AM (in response to jjsantoro)Hi Santoro,
You need to follow these steps if u want process data in rules.
IN - Code
Apporach 1
U need to put process instance in working memory so that the rule can evaluate the conditions in when part.
a. Do this In a script task just after start node kcontext.getKnowledgeRuntime().insert(kcontext.getProcessInstance())
Approach 2
Or Register a Process event listener, and in afterProcessStarted() event add this line session.insert(event.getProcessInstance())
IN - RULES
Sample Rule 1 :
import org.drools.runtime.process.WorkflowProcessInstance;
when $process: WorkflowProcessInstance()
eval(Integer.parseInt((String)$process.getVariable("piAgeVariable")) > 30)
then .........
Notes :
1. I am not sure about JBPM-6, but in JBPM 5.4 if u don't fire the rule when u enter the node, then rule is not fired. Resolution to this is Be sure that u have placed this line just before u enter the rules node. ksession.fireAllRules(); .
2. Keep one thing in mind to retract the process instaces properly after rule node is executed using the kcontext.getKnowledgeRuntime().retract() or the eventListener approach. Else this process instance will remain in working memory and will be part of rules evaluation when anyother JBPM process instance triggers fireAllRules().
-
2. Re: Invoking a business rule from a process
swiderski.maciej Jan 2, 2014 4:16 AM (in response to ahmedza)on top of what was already mentioned you can take advantage of data input and output (and their associations) on business rule task to insert and the retract the data from working memory. Take a look at screen cast 3 on this blog post. It guides you through using rule task in process in jbpm6.
HTH
-
3. Re: Invoking a business rule from a process
jjsantoro Jan 3, 2014 2:01 PM (in response to swiderski.maciej)Maciej,
Thank you for the blog. I was able to reproduce your process and make my own. My problem was that I named a project with mixed case, but the forms and process did not behave properly unless I used all lower case (e.g., my package was "MixedCase" but I had to refer to it as "org.jbpm.mixedcase".