java - How to retrieve process variable in Camunda-bpm? -


while reading (https://docs.camunda.org/manual/7.5/user-guide/process-engine/variables/) not sure how retrieve variable?

at moment struggling find out how access set process variables. tried is:

i have simple bpmn process in have start event, 1 service task , end event, starting process passing 2 variables (a&b) , service task implementing following java class:

public class addition implements javadelegate {      public void execute(delegateexecution exe) throws exception {          system.out.println("inside calculator again");          integer x = (integer) exe.getvariable("a");         integer y = (integer) exe.getvariable("b");         int add = x+y;         system.out.println("addition of 2 number is"+add);         exe.setvariable("add",add); } 

i starting process follows:

public void sayhello(processengine processengine) {     map<string,object> variables = new hashmap<string, object>();     variables.put("a", 3);     variables.put("b", 5);     processinstance instance=  processengine.getruntimeservice().startprocessinstancebykey("process_3", variables); } 

i want access add variable (present in addition class) in sayhello class? process has been completed can't use runtimeservice tried use history service couldn't find out solution.

is there java api can use or there other way?

if want historic variable instances use list method in historicvariableinstancequery.

for example

list<historicvariableinstance> variables = processengine.gethistoryservice().createhistoricvariableinstancequery.list(); 

if want specific variables given name can use method variablename(string)

for example:

list<historicvariableinstance> variables = processengine.gethistoryservice().createhistoricvariableinstancequery().variablename("myvar").list(); 

to variables of specific process instance use method processinstanceid

for example:

 list<historicvariableinstance> variables = processengine.gethistoryservice().createhistoricvariableinstancequery().processinstanceid(processinstance.getid()).variablename("myvar").list(); 

see further information documentation of historyservice , historicvariableinstancequery


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

unity3d - Fatal error- Monodevelop-Unity failed to start -