Hello,
I have a problem with running ruleflow with ForEach
node (Drools 5.0.1):
ForEach node contains two action nodes(let’s say A1 and A2) and one rule
set node(let’s say R1). I have one object, that is inserted into working
memory (let’s call it O1), and passed to process instance as a process
variable. The collection expression in ForEach node contains collection of
parameters. The nodes inside ForEach node are connected as
A1 -> R1 -> A2 so for each parameter from the
collection the following sequence is performed: in A1 the parameter is set to
O1 via setter and update(O1) is called, then the rule set R1 is activated,
where some actions are done with the object. And then, in A2, some data, which
was changed during ‘R1’ stage, is extracted from object.
The problem is that actions are not called in right
consequence. For example, for 4 elements in the collection, the sequence, in
which the nodes are triggered is following: A1,A1,A1,A1,R1,A2,A2,A2,A2 instead of A1, R1, A2, A1, R1, A2, A1, R1, A2, A1,
R1, A2
The code, used to run drools is:
Map variables = new HashMap();
variables.put(OBJECT_VARIABLE_NAME, object);
ksession.insert(object);
ksession.startProcess(processId, variables);
ksession.fireAllRules();
Can you explain such
behavior?
Thank you.