Ricardo,
If you need to access process variables and have only simple constraint
expressions, I suggest you use code constraints (Java or MVEL dialect),
as they have direct access to variables (and globals).
If you want to use rule constraints anyway (because your constraints can
become rather complex), there are a few options:
- You cannot use globals to pass information used in your constraints,
because globals are considered immutable with respect to rule conditions
- You can put your data you want to access in your working memory.
Rule constraints can then access this info just like any normal rule.
- You access the variable value using the special "processInstance"
rule constraint (I just added a new section in the documentation to
explain):
Rule constraints do not have direct access to variables defined inside
the process. It is however possible to refer to the current process
instance inside a rule constraint, by adding the process instance to the
working memory and matching to the process instance inside your rule
constraint. We have added special logic to make sure that a variable
"processInstance" of type WorkflowProcessInstance will only match to the
current process instance and not to other process instances in the
working memory. Note that you are however responsible yourself to insert
(and possibly update) the process instance into the session (for example
using Java code or an (on-entry or on-exit or explicit) action in your
process). The following exampleof a rule constraint will search for a
person with the same name as the value stored in the variable "name" of
the process:
processInstance: WorkflowProcessInstance()
Person( name == ( processInstance.getVariable("name") ) )
# add more constraints here ...
Kris
Quoting Ricardo Gil Alcañiz <rgil(a)okode.com>:
Hi,
I'm not a new drools user but I started to test rule flows (5.0M5)
recently
and I'm stucked, so any clue will be welcomed :). I'm testing how to
share a
StatefulKnowledgeSession between N rule flow instances. I'm trying
to
parametrize each instance with process variables at start time but I
don't
know how to use them from rule constraints (in event waits, splits,
etc.).
I've read the documentation and I've found this text related to
constraints
"Both rule and code constraints have access to globals that are
defined for
the process and can reuse imports at the process level." I tried it
assigning (from an action) a variable value to a global variable but
it's
not working for me. ¿I'm missing something?
Thanks in advance!
Ricardo.