I found this related thread http://drools.46999.n3.nabble.com/Rule-tasks-and-gwt-console-td1711764.html, but the answer does not make things much clearer for me...
Where do I have to change these things, in my ProcessTest.java?
I'm not sure if I understood the question, but if what you need is to access process variables inside your rules, you can use something like this:
rule A ruleflow-group "ABC" when $process: WorkflowProcessInstance() then Map variable = (Map)((WorkflowProcessInstance)kcontext.getKnowledgeRuntime().getProcessInstance($process.getId())).getVariable("variableName");
Thanks very much for your reply Esteban.
I am sorry for being a bit unclear. It is my writing style, and I am working on it to define problems in a more clear way :-)
So, if I have a variable "monkey" in my BPMN process (which is added to the map btw), where the user has given a value to in an .ftl form, let's say "chimp". And I want a rule to fire based on the value "chimp" I would write something like:
(Map)((WorkflowProcessInstance) kcontext.getKnowledgeRuntime().getProcessInstance(WorkflowProcessInstance(.getId())).getVariable("monkey") == "chimp";
(Map) (WorkflowProcessInstance (kcontext.getKnowledgeRuntime().getProcessInstance(WorkflowProcessInstance().getId()).setVariable("character") = "nice";
I realise I can store the path into a variable to shorten the code. But this is what it would come down to I guess?
I am retrieving the variable from the map, is this neccesary or can it be ommitted?
I assum to set variables I use setVariable, am I right?
The LHS of your rule is wrong. I think you need to use an eval() if you want to invoke methods that contains parameters.
I also remembered another way to get process variables in the RHS, but I don't remember if it has some caevats:
String monkey = (String)$processInstance.getVariable("monkey"); //This will return "chimp"
Thnx again Esteban!
It seems that the class WorkflowProcessInstance cannot use the methods get/setVariable. Googling on it brings me e.g. to the v3 of jbpm showing that only ContextInstance can use get and set.
Which brings me to the question if "kcontext" can be used in a DRL file without imports. If not, what should be imported and must kcontext be declared in the drl file?
I still have not found a way to access, eval and change process variables in a drl file...
The following rules do not seem to fire. I have included ksession.fireUntilHalt() in my procestest. Do I miss anything else?!
$proces : WorkflowProcessInstance()
$partij : String() from (String)$proces.getVariable("conflictpartij");
eval($partij == "overheid");
#include attributes such as "salience" here...
$proces : WorkflowProcessInstance();
Sorry, I forgot to mention that the WorkflowProcessInstance object is not a fact by default. You need to insert it before the Rule Node is executed. One way to do this is to add a Script Task node that executes:
So you did, it seems :-) It is working now, I cannot thank you enough for sharing this information.
I think ppl with similar problems will solve it reading this thread. If not, I am happy to share the information!
I have the same problem what leon has. I have added to my fisrt human task at the entry action the kcontext.getKnowledgeRuntime().insert(kcontext.getProcessInstance()); script. My rule currently look like this :
processInstance : WorkflowProcessInstance()
age: Integer() from (Integer)((WorkflowProcessInstance)processInstance).getVariable("Age");
eval(age < 18);
processInstance.setVariable("Name", new String("Denied"));
If I am removing the age declaration with eval(true) the rule is fired and the name is set to Denied. The compiler accept the declaration, no errors during te running phase, but the rule is not fired.
Can you help me plese? I am doing my master thesis and this is also a small part of it.
Thank you in advance.
Kind regards, Hunor
Is it possible to do this from guvnor?
How do you import org.drools.runtime.process.WorkflowProcessInstance in the rule file?
Note: I am using JBPM 5.3