How to define a variable in a userTask and use that?

Hi
Please have a look at this model:

As you can see, I created 3 userTasks.
I’ve created task listeners with complete event type for user1 and user2.
which have these scripts:

user1:
int x = 5;

user2:
int x = 4;

Then, I’ve created a task listener with create event type for user3.
which has this script:

if (x == 5){
task.setAssignee("reviewerID");
}

When I run the process, I face this error:

No such property: x for class: Script4'

Which is quite to be expected. because I didn’t define the x variable inside user1’s task listener.

But also, value of x will never be equal 5, if I define the x inside the user1. something like this:

int x;
if (x == 5){
task.setAssignee(“reviewerID”);
}

And the if condition never will be true and the task.setAssignee("reviewerID"); never will be executed.

I’ll be grateful if you guide me on how can I define that variable, also using that in the user3.

Hi @rezza72

you should declare a variable with the following code:
task.setVariable(“x”,5)