yes you are right.. did you try removing the insert cmd from the second code snippet?
just to have the same scenario?
The first code should fail as the second. With the message Unexpected global [test2]

On Tue, Jun 22, 2010 at 8:40 AM, Samuli Saarinen <samuli.saarinen@remion.com> wrote:
Actually I am trying to set an unexistent variable (test2) in both
snippets. But for some reason only the second one produces the exception.

Samuli

Salaboy wrote:
> Well, in the second code snippet you are trying to set an unexistent
> variable called test2. For setting a global variable you need to
> define it first in the drl file. Greetings!
>
> - CTO @ http://www.plugtree.com
> - MyJourney @ http://salaboy.wordpress.com
> - Co-Founder @ http://www.jbug.com.ar
> - Mauricio "Salaboy" Salatino -
>
> On Jun 22, 2010, at 4:32, Samuli Saarinen <samuli.saarinen@remion.com>
> wrote:
>
>> Hello,
>>
>> I'm new to drools and have problems with globals or with the different
>> behaviour of drools depending on how the globals are specified.
>>
>> I have the following simple rule:
>>
>> global String test
>>
>> rule "Global"
>>   when
>>   then
>>     System.out.println(test);
>> end
>>
>> If i run the rule with:
>>
>> KnowledgeBase kb = getKnowledgeBase("global.drl");
>> StatelessKnowledgeSession ses = kb.newStatelessKnowledgeSession();
>> ses.setGlobal("test2", "foo");
>> ses.execute("");
>>
>> I get the expected result of null printed
>>
>> but if I use commands:
>>
>> KnowledgeBase kb = getKnowledgeBase("global.drl");
>> StatelessKnowledgeSession ses = kb.newStatelessKnowledgeSession();
>> List<Command<?>> cmds = new ArrayList<Command<?>>();
>> cmds.add(CommandFactory.newSetGlobal("test2", "bar"));
>> cmds.add(CommandFactory.newInsert(""));
>> ses.execute(CommandFactory.newBatchExecution(cmds));
>>
>> I get java.lang.RuntimeException: Unexpected global [test2]
>>
>> Why is the behaviour different and which one is correct?
>>
>> Regards,
>>
>> Samuli
>>
>>
>> --
>> Remion Oy           Etävalvontajärjestelmät liiketoiminnan
>> Samuli Saarinen           tehostamiseen
>> gsm +358 (0)50 3560075
>> fax +358 (0)3 2125064       www.remion.com
>> _______________________________________________
>> rules-users mailing list
>> rules-users@lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>
> _______________________________________________
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
> --
> STOP Virus, STOP SPAM, SAVE Bandwidth!
> http://www.safentrix.com/adlink?cid=0
> -



--
Remion Oy           Etävalvontajärjestelmät liiketoiminnan
Samuli Saarinen           tehostamiseen
gsm +358 (0)50 3560075
fax +358 (0)3 2125064       www.remion.com
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users



--
- CTO @ http://www.plugtree.com  
- MyJourney @ http://salaboy.wordpress.com
- Co-Founder @ http://www.jbug.com.ar

- Salatino "Salaboy" Mauricio -