You're doing nothing wrong. At least, as long as you want it to print twice. :) Two activations are put on the agenda because both patterns (X+Y and X+Z) are in working memory.
Probably your best bet is to split it into two rules in an activation-group.
rule "Cannot select X if both Y and Z are not selected" activation-group foo
when
Item(code == "X")
not Item(code == "Y")
then
System.out.println("Error: You cannot select X unless both Y and Z are selected");
end
rule "Cannot select X if both Y and Z are not selected"
activation-group foo
when
Item(code == "X")
not Item(code == "Z")
then
System.out.println("Error: You cannot select X unless both Y and Z are selected");
end
Activation of one rule will prevent activation of the other one, resulting in only one error message.
--- On Mon, 12/1/08, Vithal Kuchibhotla <vithalklrk@rediffmail.com> wrote:
From: Vithal Kuchibhotla <vithalklrk@rediffmail.com> Subject: [rules-users] Action firing twice To: rules-users@lists.jboss.org Date: Monday, December 1, 2008, 11:20 PM
Hello All, I have a list of Items that I am inserting into working memory. Here is the rule that is failing: rule "Cannot select X if both Y and Z are not selected"when Item(code == "X") (or (not Item(code == "Y")) (not Item(code == "Z")))then System.out.println("Error: You cannot select X unless both Y and Z are selected");endThis rule works correctly when X and Y are there, and when X and Z are there. However, when both Y and Z are missing, the
error prints twice. Can anyone tell me what I am doing wrong. Thanks a lot Vithal
_______________________________________________ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
|