# Issue with camunda 7 groovy script

**URL:** <https://forum.camunda.io/t/issue-with-camunda-7-groovy-script/54256>\
**Category:** Camunda 7 Topics\
**Created:** [August 15, 2024, 10:16am UTC](https://forum.camunda.io/t/issue-with-camunda-7-groovy-script/54256 "2024-08-15T10:16:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mason\_John](https://forum.camunda.io/user_avatar/forum.camunda.io/mason_john/32/29964_2.png) [@Mason\_John](https://forum.camunda.io/u/Mason_John)\
**Post date:** [August 15, 2024, 10:16am UTC](https://forum.camunda.io/t/issue-with-camunda-7-groovy-script/54256/1 "2024-08-15T10:16:06Z")

</div>

I have a string json in my camunda variable like this [{“roleCode”:“OWNE”,“roleName”:“Người vay”,“perName”:“AAA”,“nationalityCode”:“VIETNAM”,“nationalityName”:“AAA”,“startDate”:null,“endDate”:null,“identityType”:null,“content”:null}]

then in my bpmn model in node service task I use groovy script inline to get it  
def json = execution.getVariable(“GeneralCriteriaCountryNationJson”)

then I convert it to json using spin put to camunda variable as type json  
def v = Spin.JSON(json)  
then I override GeneralCriteriaCountryNationJson variable with execution.setVariable(“GeneralCriteriaCountryNationJson”, v)

when I check in camunda GeneralCriteriaCountryNationJson still type string not json but when I change execution.setVariable(“GeneralCriteriaCountryNationJson2”, v) new variable will set as json type. Is any way to fix this problem thanks.

---

<div class="post-metadata">

**Author:** ![WilliamR.Alves](https://forum.camunda.io/user_avatar/forum.camunda.io/williamr.alves/32/27412_2.png) [@WilliamR.Alves](https://forum.camunda.io/u/WilliamR.Alves)\
**Post date:** [August 16, 2024, 4:12pm UTC](https://forum.camunda.io/t/issue-with-camunda-7-groovy-script/54256/2 "2024-08-16T16:12:34Z")

</div>

Hello my friend!

I believe this happens because Camunda still keeps a reference to the previously created variable.

One thing that might help you is…

Instead of creating a new variable, you can remove the variable and then recreate it again.

example:

```auto
def json = execution.getVariable(“GeneralCriteriaCountryNationJson”);
def v = Spin.JSON(json);

execution.removeVariable("GeneralCriteriaCountryNationJson");

execution.setVariable("GeneralCriteriaCountryNationJson", v);

```

I hope this helps!  
**William Robert Alves**

---

<div class="post-metadata">

**Author:** ![WilliamR.Alves](https://forum.camunda.io/user_avatar/forum.camunda.io/williamr.alves/32/27412_2.png) [@WilliamR.Alves](https://forum.camunda.io/u/WilliamR.Alves)\
**Post date:** [August 16, 2024, 4:17pm UTC](https://forum.camunda.io/t/issue-with-camunda-7-groovy-script/54256/3 "2024-08-16T16:17:30Z")

</div>

NOTE:

If you were using JavaScript in your script, I believe this behavior would be different, and the type of the variable would also be overwritten when overwriting the variable… I’m not sure, but you can do some tests, because as far as I remember, I’ve had problems similar to yours.

**William Robert Alves**

---

<div class="post-metadata">

**Author:** ![Mason\_John](https://forum.camunda.io/user_avatar/forum.camunda.io/mason_john/32/29964_2.png) [@Mason\_John](https://forum.camunda.io/u/Mason_John)\
**Post date:** [October 2, 2024, 2:53am UTC](https://forum.camunda.io/t/issue-with-camunda-7-groovy-script/54256/4 "2024-10-02T02:53:26Z")

</div>

Thanks for reply. I figured out my situation. I forgot that in the next step I had set this variable again. So it my bad 🙂

---

<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:** [December 31, 2024, 2:53am UTC](https://forum.camunda.io/t/issue-with-camunda-7-groovy-script/54256/5 "2024-12-31T02:53:37Z")

</div>

Closed on December 31, 2024, 2:53am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
