How can I access Input Parameter from Modeler in Service Task

I have following BPMN:

startandPost.bpmn (3.2 KB)

Is it possbile, that I declare in Modeller Variables like ints, Strings or something, that I can access while the Service Task is running ? What would a example code for Java Spring Boot ?

Thought about:

@andii04 - You can try the below code in your java delegate associated with the service task

String duration= (String) execution.getVariableLocal(“duration”);

1 Like

Thanks this works for me! Is it possible to make it “global” so that I can reache this variable from other Classes ?

By default when you pass the variables from the ‘Input’ tab they become local variables .If you want some variable to be global you can use execution.setVariable('myGlobalVar;,‘this is global variable’)

1 Like

Global scope:


Local scope:

1 Like

I want to set the variable in Modeler, then I have it local in my Code (String duration = (String) execution.getLocalVariable(“duration”) , after I got it, I have to set it immediately with: execution.setVariable (“duration”, duration) in Code I think, or ?

Input/Output tabs are typically used for passing variables to a reusable function and the output parameter maps to a global variable . If all you need is a global variable you can add a scrip task and select javascript as format with mode inline and have the code in it as execution.setVariable(‘duration’,‘duration’)

Thanks, but I need a Possibility that I can set Variables in Modeler directly, without any knowing of Programming or Java Script Code, I can read this variable in Java Code and transform it to a global variable. It should possible, that another person without knowing Coding in Java/JavaScript or whatever Language easily use the Modeler for setting easily variables for the process and can switch variables like times duration in seconds with just change one value in Modeler.

Hi @andii04,

building on @dineshsb’s last answer, you can simply create the output parameter as type Text and write the following expression as value: ${duration}. This will pick up the local variable called duration and make it available globally. The Name of the output parameter will then be the name of the variable in the global scope. No Java or JavaScript knowledge necessary.

Hint: It is usually advisable to have different names for the local variables in order to not get too confused with variable names. But it works nonetheless.


1 Like

You mean it so?:

durationglob will pickup the value from duration (Input) and then be global accessable ? How can I get this globalvariable ‘durationglob’ in Java ?

Yes, correct.

Well, depending on your context, you can use the execution.getVariable("durationglob") or runtimeService.getVariable("executionId", "durationglob"). Have a look at the documentation for further info on that:


1 Like