Process Variables

Hello All,

I am new to BPMN and Camunda-bpm.I have a simple bpmn process in which i am using 1 service task.I want to execute my process by using processEngine.getRuntimeService().startProcessInstanceByKey(“Process_1”, variables);
where my variables is as follows:

Map<String,Object> variables = new HashMap<String, Object>();
variables.put(“a”, 2);
variables.put(“b”, 5);

Now my service task is implementing a java class in which i want to use process variable “a” and “b”?
How can i get same process variable “a” and “b” in that class?

Any help is appreciated.

Thanking you
Keshav Kumar Taparia

The class that you used to implement your service task needs to use the JavaDelegate interface.
Then you’ll have a an execute method…

That method in turn contains a DelegateExecution variable and you can used that to get and set variables like this:

package org.camunda.demo.Berlin.ApplicationReview;

import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;

public class ChooseReviewersDelegate implements JavaDelegate {

    @Override
    public void execute(DelegateExecution exe) throws Exception {


        String a = (String) exe.getVariable("a");
        exe.setVariable("UserIDOne", "john");
        exe.setVariable("UserIDTwo", "mary");
        exe.setVariable("UserIDThree", "demo");

    }

}


1 Like

Hi,

please have a look at the user guide.

Cheers,
Sebastian

1 Like

Hello Niall,

Thanks for your prompt reply.Actually i am using karaf environment in which i created process engine by following this example(https://github.com/camunda/camunda-bpm-platform-osgi) so my service class is not implementing JavaDelegate.

I have a ExampleProcessApplication class which extends OSGiProcessApplication class and looks like as follows:

‘’’
public class ExampleProcessApplication extends OSGiProcessApplication {

private RuntimeService runtimeService;
Map<String,Object> variables = new HashMap<String, Object>();

public ExampleProcessApplication(BundleContext ctx, BlueprintContainer blueprintContainer) {
	super(ctx.getBundle(), blueprintContainer);	
}

@PostDeploy
public void sayHello(ProcessEngine processEngine) {
	try {
		variables.put("a", 2);
		variables.put("b", 5);
		processEngine.getRuntimeService().startProcessInstanceByKey("Process_1",variables);
			} catch (Exception e) {
		e.printStackTrace();
	}
}

}
‘’’
I used blueprint service and using beans my service task is implementing this class as follows:
‘’’
public class Calculator {

public void Addition()
{	
}
public void Multiply()
{	
}

}
‘’’
How can i use my process variables here?

Thanking you
Keshav Taparia

Dear menski,

I went through user guide again same problem arise that my implementation class is not implementing JavaDelegate interface.

Let me repeat my complete problem again.
I am using karaf environment in which i created process engine by following this example(https://github.com/camunda/camunda-bpm-platform-osgi) so my service class is not implementing JavaDelegate.

I have a ExampleProcessApplication class which extends OSGiProcessApplication class and looks like as follows:
‘’’
public class ExampleProcessApplication extends OSGiProcessApplication {

private RuntimeService runtimeService;
Map<String,Object> variables = new HashMap<String, Object>();

public ExampleProcessApplication(BundleContext ctx, BlueprintContainer blueprintContainer) {
super(ctx.getBundle(), blueprintContainer);
}
@PostDeploy
public void sayHello(ProcessEngine processEngine) {
try {
variables.put(“a”, 2);
variables.put(“b”, 5);
processEngine.getRuntimeService().startProcessInstanceByKey(“Process_1”,variables);
} catch (Exception e) {
e.printStackTrace();
}
}
‘’’
I used blueprint service and using beans my service task is implementing this class as follows:
‘’’
public class Calculator {

public void Addition()
{
}
public void Multiply()
{
}
}
‘’’
How can i use my process variables here?

Thanking you
Keshav Taparia

1 Like

Hi @k.taparia,

In the future, please submit any camunda-osgi-related questions in the Community Extensions category. You can select it when you create a new thread. camunda-bpm-platform-osgi is a community extension maintained by @rbraeunlich and therefore not part of the Camunda product. If you post questions in the correct category you are more likely to receive an answer by an expert and you help us keep the forum organized.

Edit: In addition, see this post on code formatting.

Thanks and best regards,
Thorben

2 Likes