same as with java:
drools.workingmemory.setGlobal( identifier, object );
Mark
Joshua Jackson wrote:
Dear all,
How do we modify a global variable with mvel dialect inside rules file
without getting
java.lang.UnsupportedOperationException: External Variable
identifer='allowance' type='class java.lang.Double' is final, it
cannot be set
[testng] at
org.drools.base.mvel.DroolsMVELGlobalVariable.setValue(DroolsMVELGlobalVariable.java:37)
[testng] at
org.drools.base.mvel.DroolsMVELFactory.createVariable(DroolsMVELFactory.java:199)
[testng] at
org.mvel.ast.AssignmentNode.getReducedValueAccelerated(AssignmentNode.java:80)
[testng] at org.mvel.MVELRuntime.execute(MVELRuntime.java:88)
[testng] at
org.mvel.CompiledExpression.getValue(CompiledExpression.java:108)
[testng] at org.mvel.MVEL.executeExpression(MVEL.java:230)
[testng] at
org.drools.base.mvel.MVELConsequence.evaluate(MVELConsequence.java:47)
[testng] at
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:550)
[testng] at
org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:514)
[testng] at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:462)
[testng] at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:424)
This is how I did it:
Java file:
public void run(){
Double allowance = new Double(0);
workingMemory.setGlobal("allowance", allowance);
workingMemory.fireAllRules();
}
Rules:
global Double allowance
dialect "mvel"
rule "Has Wife"
no-loop
salience 20
when
e: Employee()
income:Income()
eval( e.isWife() )
then
System.out.println("Has Wife");
allowance = allowance + 5000;
end
This works if I use java as the dialect.
Have I missed something?
Thanks in advance,