[rules-users] Action firing twice

Greg Barton greg_barton at yahoo.com
Tue Dec 2 00:50:18 EST 2008


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 at rediffmail.com> wrote:
From: Vithal Kuchibhotla <vithalklrk at rediffmail.com>
Subject: [rules-users] Action firing twice
To: rules-users at 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");
end

This 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 at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20081201/0fedc42c/attachment.html 


More information about the rules-users mailing list