Is there a way to get and set the global/local variable list through code in JBPM 6?
I saw the documentation for JBPM version 3 like below:
ProcessInstance processInstance = ...;
ContextInstance contextInstance = (ContextInstance) processInstance.getInstance(ContextInstance.class);
But this seems deprecated, and gives me an error.
Additionally, I can set the variables through the bpmn editor using
kcontext.setVariable("isApproved", false);
But I'm not quite sure how to do retrieve this kcontext variable in code. I went through the getter methods for both an KieSession object and a ProcessInstance object, but no luck.
Update:
I can access these local variables through the params map object which is passed to the ksession.startProcess(...) method. Is this the only way to get/set local/global variable lists?
Thanks!
Here is how I have been accessing my process variables
String variableName = "Your_Variable_Name_here";
KieSession ksession = runtime.getKieSession();
ProcessInstance pi = ksession.getProcessInstance(processInstanceId);
RuleFlowProcessInstance rfpi = (RuleFlowProcessInstance)pi;
Object variable = rfpi.getVariable(variableName);
You should then cast your variable into the proper class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With