[rules-users] Can I insert a fact from within a drl function?
Wolfgang Laun
wolfgang.laun at gmail.com
Wed Feb 8 01:55:36 EST 2012
insert and its cousins all depend on a context where the variable drools is
defined and supplie by the parser, and this is restricted to consequence code.
import org.drools.runtime.KnowledgeContext;
function makeFact( KnowledgeContext kContext, ... ){
Fact f = new Fact( ... );
kContext.getKnowledgeRuntime().insert( f );
}
then
makeFact( kcontext, ... );
end
-W
On 07/02/2012, Shur, Bob <robert.shur at hp.com> wrote:
> It seems I am unable to insert a new fact from within a drl function. I
> tried this:
>
> ////////////////////////
> package com.sample
>
> declare Dummy
> end
>
> function void init() {
> insert(new Dummy()); // Doesn't compile
> }
>
> rule "init"
> salience 999
> when
> then
> init();
> insert(new Dummy()); // Compiles
> end
>
> ////////////////////////
>
> Is the above supposed to work?
>
> _______________________________________________
> 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