I am currently starting to work with jbpm/drools and tried to modify some process variables from my DRL using the "Business Rule Task". I tried the following with a process, which declared a variable "var" of type "MyCustomObject".
Following the results of this question and this recommendation I created a Task which should execute the ruleflow-group "testgroup" and has the following onEntry script:
kcontext.getKnowledgeRuntime().insert(kcontext.getProcessInstance());
My DRL now looks like this:
import mypackage.MyCustomObject;
import org.kie.api.runtime.process.WorkflowProcessInstance;
rule "generate object"
ruleflow-group "testgroup"
when
//some stuff applies
then
insert(new MyCustomObject());
end
rule "modify variable"
ruleflow-group "testgroup"
when
$process: WorkflowProcessInstance()
$obj: MyCustomObject()
then
WorkflowProcessInstance $p = (WorkflowProcessInstance)kcontext.getKieRuntime().getProcessInstance($process.getId());
$p.setVariable( "var", $obj);
System.out.println("Value of object in memory: "+$obj);
System.out.println("Value of object in variable:+$p.getVariable("var"));
retract($process);
end
After the Business Rule Task, I placed a simple Script Task:
if(var != null) {
System.out.println("var: "+var);
} else{
System.out.println("var is null!");
}
The output I get is now (Note: MyCustomObject does not override toString):
Value of object in memory: MyCustomObject@XYZ
Value of object in variable: MyCustomObject@XYZ
var is null!
At this point I have no idea, what went wrong. As implied by the output, the ProcessInstance in the working memory has correctly set its variable, but the value is not present in the process itself (ergo for other nodes to access).
Additional Information:
I currently use the workbench version 6.4.0.Final on a JBoss EAP 6.4 and deploy the containers to a KieExecutionServer (6.4.0.Final) running on a separate EAP 6.4 instance.
Any suggestions are appreciated.