[rules-users] Setting Globals inside Rules

Edson Tirelli tirelli at post.com
Tue Sep 30 10:29:57 EDT 2008


   You can have a setup rule with high-salience or specific agenda-group (or
whatever other flow control mechanism you want) firing first and setting the
values in its consequence, but you MUST fire this rule before asserting your
facts into the working memory, because I guess you will be using these
globals in the LHS of other rules.

   So the code of your application would be like:

* create rulebase
* create session
* set focus on "setup"
* fire setup rule
* assert facts
* fire rules

    The setup rule would be like:

rule "setup rule"
    agenda-group "setup"
when
then
    // set globals like this:
    drools.getWorkingMemory().setGlobal( "myGlobal", someValue );
end

   []s
   Edson



2008/9/30 Gary Napier <gnapier at cis.strath.ac.uk>

> Hi all,
>
> I have common code that can run a number of different rule base(s) and so
> far each of the different rule bases have utilized common Global variables
> (lists of regular expressions and runtime options)
>
> However a new rule base will require additional /different globals to be
> set and i do not want to change the code that invokes the engine and
> compiles the rule base.
>
> Is it possible, by way of an example, to have a rule execute upon rule base
> initialization and populate a series of global variables? Ideally this would
> come from a settings config file in the same directory as the
> rule .drl files.
>
> Thanks
> Gary
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



-- 
 Edson Tirelli
 JBoss Drools Core Development
 JBoss, a division of Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20080930/31d421c0/attachment.html 


More information about the rules-users mailing list