[rules-users] Ways to list the globals

Davide Sottara dsotty at gmail.com
Wed May 1 21:35:54 EDT 2013


I guess the answer depends on what you are trying to do...

Getting the names of the globals in a knowledge base is effectively
a bit tricky and may be worthy a feature request JIRA.
You would have to look into each KnowledgePackage in the KnowledgeBase:

for ( KnowledgePackage pkg : 
drools.getKnowledgeRuntime().getKnowledgeBase().getKnowledgePackages() ) {
    .... pkg.getGlobalVariables();
}

This should give you ALL the **NAME-TYPE** declarations, regardless of
whether
a global is set or not.


Getting the key-value pairs of globals set at runtime can be done
using the knowledgeRuntime.getGlobals(), as in your first option.

This should give you ALL the **NAME-VALUE** pairs which have been set,
regardless of whether that was done from java or within the DRL.

If this is not the case, please post your rule, code and Drools version,
so that it will be possible to check whether this is a bug or not.
The engine seems to behave correctly on the 5.6.x master development branch.

Best
Davide



On 05/01/2013 06:01 PM, Sonata wrote:
> Hi, I am trying to list out the globals but I am confused, please help.
>
> I wrote this line in my drl file
> ((MapGlobalResolver)drools.getKnowledgeRuntime().getGlobals()).getGlobals()
> this gives me ONLY the globals that I have added in drl through
> drools.getWorkingMemory().setGlobal()
> this does not list out the globals that I have added in java before firing
> the rules.
>
> Then I tried this line in my drl file
> drools.getKnowledgeRuntime().getKnowledgeBase().getKnowledgePackages().getGlobalVariables()
> this gives me BOTH the globals that I have added in drl through
> drools.getWorkingMemory().setGlobal()
> AND the globals that I have added in java before firing the rules.
>
> My question is, to list the useable globals in the current rule, what is the
> correct method call?
>
> Thank you
>
>
>
> --
> View this message in context: http://drools.46999.n3.nabble.com/Ways-to-list-the-globals-tp4023616.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> 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