# setVariable() using value parameter of another process variable name (javascript)

**URL:** <https://forum.camunda.io/t/setvariable-using-value-parameter-of-another-process-variable-name-javascript/3693>\
**Category:** Discussion & Questions\
**Tags:** process-engine\
**Created:** [May 19, 2017, 4:30pm UTC](https://forum.camunda.io/t/setvariable-using-value-parameter-of-another-process-variable-name-javascript/3693 "2017-05-19T16:30:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![StephenOTT](https://forum.camunda.io/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@StephenOTT](https://forum.camunda.io/u/StephenOTT)\
**Post date:** [May 19, 2017, 4:30pm UTC](https://forum.camunda.io/t/setvariable-using-value-parameter-of-another-process-variable-name-javascript/3693/1 "2017-05-19T16:30:35Z")

</div>

[@camunda](https://forum.camunda.io/groups/camunda) can someone explain this system behaviour (and assuming this is not a bug, the reasoning/use case).

Consider the following:

![](https://forum.camunda.io/uploads/default/original/2X/0/0a42d38e6ce70797184ba5333e1d4015411aaa2c.png)

“create variable”: contains the following javascript:

```auto
execution.setVariable("myTestVar", "value123");

```

“Create second variable”: contains the following javascript:

```auto
execution.setVariable("myTestVar2", myTestVar);

```

![](https://forum.camunda.io/uploads/default/original/2X/8/88938af8a86e8ec5bc599861eef224e8a51153c0.png)

If you run this, no errors are thrown and `myTestVar2` is created with the process variable value of `myTestVar`. Why is the myTestVar value available to the second task when it is placed as the value parameter of the `setVariable()` method?

If the second task’s script was just:

```auto
myTestVar;

```

the script would error out and not be able to find the variable.

Is this the expected behaviour? if so, why?

Thanks!

---

<div class="post-metadata">

**Author:** ![aakhmerov](https://forum.camunda.io/user_avatar/forum.camunda.io/aakhmerov/32/413_2.png) [@aakhmerov](https://forum.camunda.io/u/aakhmerov)\
**Post date:** [May 22, 2017, 6:53am UTC](https://forum.camunda.io/t/setvariable-using-value-parameter-of-another-process-variable-name-javascript/3693/2 "2017-05-22T06:53:28Z")

</div>

Hi @StephenOTT,

I think this happens due to the definition of “scope”. Variable scope and scope available to javascript engine are not equal. When you use setter method, variable substitution will take place and value will be used as a reference to set real value of myTestVar2 into process instance variable scope. While javascript is just not aware of such mechanic.

Does that make sense to you?  
Askar

---

<div class="post-metadata">

**Author:** ![StephenOTT](https://forum.camunda.io/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@StephenOTT](https://forum.camunda.io/u/StephenOTT)\
**Post date:** [May 22, 2017, 2:59pm UTC](https://forum.camunda.io/t/setvariable-using-value-parameter-of-another-process-variable-name-javascript/3693/3 "2017-05-22T14:59:41Z")

</div>

Is this a expected /planned behaviour? Or just a result of the script engine’s functionality? If it was expected, is there a specific use case for such functionality?

---

<div class="post-metadata">

**Author:** ![aakhmerov](https://forum.camunda.io/user_avatar/forum.camunda.io/aakhmerov/32/413_2.png) [@aakhmerov](https://forum.camunda.io/u/aakhmerov)\
**Post date:** [May 23, 2017, 7:40am UTC](https://forum.camunda.io/t/setvariable-using-value-parameter-of-another-process-variable-name-javascript/3693/4 "2017-05-23T07:40:36Z")

</div>

For me making variables provided or copied into JS scope during execution would be a feature request. If it was explicitly planned like this is out of my knowledge.

Cheers,  
Askar

---

<div class="post-metadata">

**Author:** ![system](https://forum.camunda.io/uploads/default/original/3X/5/8/58d50142eacca605d35cb1ef9e6b86ae85f49436.png) [@system](https://forum.camunda.io/u/system)\
**Post date:** [January 30, 2024, 10:52am UTC](https://forum.camunda.io/t/setvariable-using-value-parameter-of-another-process-variable-name-javascript/3693/5 "2024-01-30T10:52:31Z")

</div>

Closed on January 30, 2024, 10:52am UTC


