cancel
Showing results for 
Search instead for 
Did you mean: 

Passing parameters to Java classes

borisjan
Champ in-the-making
Champ in-the-making
Hi,

I have read the documentation to my best ability but still is not sure how to do the following (if possible at all):

I would like to execute Java code (service task) passing in a variable number of possible varying parameters. I.e. a set of name/values that the Java code would use for its execution. The variables should not be global since this would pollute the process context and I might want to call the Java task a number of times with varying values.. As far as I can see the injection mechanism require named fields in the Java class corresponding to parameters stated in the process definition so that won't do the trick for me..

Any suggestions? Is this possible at all in Activiti/BPMN 2.0?

I looked at the scripting task and as far as I can see it does not support passing in parameters to the script but only using "global" process variables.
12 REPLIES 12

frederikherema1
Star Contributor
Star Contributor
You can use the runtimeService.startProcessInstanceByXXX(…, variables). The map op variables you pass in will be available throughout the workflow (in expressions, javadelegates, …).

solanki
Champ in-the-making
Champ in-the-making
Hi,

Do we have something like this in activiti as of today. Basically my use-case is there is a generic Service task having no Expression Fields, this Generic Service task routes to a specific service task by calling Specific service task execute method. And this specific task contains the required expression fields

The templates using the Generic service task have many activiti extension field, but my generic service task has no knowledge of them and hence fails to instantiate, can we some how instantiate it and then use the execution variable to extract values of expressions instead.

Nut shell is it possible to instantiate a generic service task having no expression fields and the extension fields are passed in the execution environment variable.

Thanks
Solanki

jbarrez
Star Contributor
Star Contributor
Yes, you can use an expression ${myBean.someMethod(someParam)}, but in that case you need to either
- use Spring and myBean is a Spring bean
- make the bean known to the engine by adding it via processEngineConfiguration.setBeans()