Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get and set Local Variable List for a process in JBPM 6?

Tags:

java

jbpm

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!

like image 853
LifeAndHope Avatar asked Dec 06 '25 11:12

LifeAndHope


1 Answers

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.

like image 93
Mike Avatar answered Dec 08 '25 01:12

Mike



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!