cancel
Showing results for 
Search instead for 
Did you mean: 

How do i use variables defined in the Script Task in the User Task?

asheerabbas
Champ on-the-rise
Champ on-the-rise

Declaring variables in Script Task through execution.setVariable and using them in the User Task.

I have declared a variable in Script Task using execution.setVariable in the activiti Designer, but when i use the same variable through the ${expression} in the usertask and i click on the submit button when the process is run it says unable to evaluate expression.

This is what i have done.

Script Task:

message = "Hello"

execution.setVariable("msg", message)

User Task

Form Properities (String):

Expression:

${msg}

Format of the script is groovy.

Please Advice

1 ACCEPTED ANSWER

Thankyou so much Jonathan, i will look in to the variable section. Further more i figured out another way, there is a field where you can name a variable in the form properties right under the expression field, so i gave a name over there and it worked like a charm.

View answer in original post

5 REPLIES 5

jearles
Star Contributor
Star Contributor

Asheer,

I believe when you use: execution.setVariable("msg", message), that's meant to set a Process Variables. From my understanding Activiti will not define a new variable for you if it doesn't already exist in the process, for example that "msg" value in your script. You would need to have a Process Variable named msg in order to store that information there.

Below is a GUI method for declaring a process variable:

 

Feel free to look into the Variables section of the User Guide for more specifics on utilization and declarations.

Hope this helps,
-JEarles

Thankyou so much Jonathan, i will look in to the variable section. Further more i figured out another way, there is a field where you can name a variable in the form properties right under the expression field, so i gave a name over there and it worked like a charm.

Hi Jonathan, 

I looked out for the Variable in the GUI shown above in your screenshot, but my designer doesn't show that option.

I'm currently using Activiti Explorer 5.22.

Thanks.

jearles
Star Contributor
Star Contributor

Asheer, 

My apologies - I'm glad you found your answer - but I was completely in left field in my original response.
You should be absolutely be okay using execition.setVariable() & task.setVariable() without ever defining them in the UI registries.

Glad you're back in working order Smiley Happy
-JEarles

Thank you for help Smiley Happy