[rules-users] Can I change the value of a global in a rule consequence?

Wolfgang Laun wolfgang.laun at gmail.com
Thu Feb 9 02:04:15 EST 2012


Done right, it works.

The variable m you have in a consequence functions very much like a
value parameter, set anew for each execution of each consequence.
Actually, all globals reside in some central repository from where they
are fed into any consequence execution.

Therefore, there is just one way of setting a global.

-W

On 09/02/2012, Shur, Bob <robert.shur at hp.com> wrote:
> The manual says "It is strongly discouraged to set or change a global value
> from inside your rules..." but it doesn't say it won't work.
>
> I tried this:
>
> ========================
> global Integer m;
>
> declare DoneInit end
>
> rule "init"
> when
> then
> 	insert(new DoneInit());
> 	System.out.println("m from Java: " + m);
> 	m = 100;
> 	System.out.println("m modified in init: " + m);
> end
>
> rule "use it"
> when
> 	DoneInit()
> then
> 	System.out.println("use m: " + m);
> end
> ==========================
>
> and got this output:
>
> m from Java: 13
> m modified in init: 100
> use m: 13
>
> Is this the expected behavior?  I'm in a stateless session in case that
> matters.
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



More information about the rules-users mailing list