# Variable scope

**URL:** <https://forum.uipath.com/t/variable-scope/199436>\
**Category:** Studio\
**Tags:** variable, question, studio\
**Created:** [March 4, 2020, 1:09am UTC](https://forum.uipath.com/t/variable-scope/199436 "2020-03-04T01:09:33Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![MadhuK](https://avatars.discourse-cdn.com/v4/letter/m/9f8e36/32.png) [@MadhuK](https://forum.uipath.com/u/MadhuK)\
**Post date:** [March 4, 2020, 1:09am UTC](https://forum.uipath.com/t/variable-scope/199436/1 "2020-03-04T01:09:33Z")

</div>

hi  
i created a boolean variable with workflow scope. i am using this variable in a for each loop within the workflow. after existing the loop the value becomes default. it is not retaining it’s value outside foreach loop. Can anybody explain why?

Thanks

---

<div class="post-metadata">

**Author:** ![Yoichi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yoichi/32/523754_2.png) [@Yoichi](https://forum.uipath.com/u/Yoichi)\
**Post date:** [March 4, 2020, 1:24am UTC](https://forum.uipath.com/t/variable-scope/199436/2 "2020-03-04T01:24:27Z")

</div>

Hi,

Can you share your workflow file?

Regards,

---

<div class="post-metadata">

**Author:** ![Nithin\_P](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/nithin_p/32/18869_2.png) [@Nithin\_P](https://forum.uipath.com/u/Nithin_P)\
**Post date:** [March 4, 2020, 4:14am UTC](https://forum.uipath.com/t/variable-scope/199436/3 "2020-03-04T04:14:39Z")

</div>

Hi @MadhuK,

Check the following:

1. Double check the scope of the variable in question. If you have not renamed the sequences, you can easily get confused with the scope.
2. Check for duplicate variables
3. The default value of Boolean variable is False (Even though you explicitly don’t assign it)

Regards,  
Nithin

---

<div class="post-metadata">

**Author:** ![Madhavi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/madhavi/32/18677_2.png) [@Madhavi](https://forum.uipath.com/u/Madhavi)\
**Post date:** [March 4, 2020, 4:45am UTC](https://forum.uipath.com/t/variable-scope/199436/4 "2020-03-04T04:45:33Z")

</div>

Seems like you have created two variables with same name but in different scope. Select the body sequence of the each loop and then check variable panel. There should be two variables. Delete the one inside the for each scope.

 ![Capture](https://global.discourse-cdn.com/uipath/original/3X/8/7/870fe253770cb2a35bfaac70dd97abef792bec5c.png)

---

<div class="post-metadata">

**Author:** ![MadhuK](https://avatars.discourse-cdn.com/v4/letter/m/9f8e36/32.png) [@MadhuK](https://forum.uipath.com/u/MadhuK)\
**Post date:** [March 4, 2020, 7:03pm UTC](https://forum.uipath.com/t/variable-scope/199436/5 "2020-03-04T19:03:58Z")

</div>

Thank you for the response. I defined my variable in sequence scope. No duplicates. Do i need to have my workflow in a flowchart for global scope?

---

<div class="post-metadata">

**Author:** ![MadhuK](https://avatars.discourse-cdn.com/v4/letter/m/9f8e36/32.png) [@MadhuK](https://forum.uipath.com/u/MadhuK)\
**Post date:** [March 4, 2020, 7:04pm UTC](https://forum.uipath.com/t/variable-scope/199436/6 "2020-03-04T19:04:31Z")

</div>

Thank you for the response. But the variable names are unique.

---

<div class="post-metadata">

**Author:** ![Madhavi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/madhavi/32/18677_2.png) [@Madhavi](https://forum.uipath.com/u/Madhavi)\
**Post date:** [March 5, 2020, 6:33am UTC](https://forum.uipath.com/t/variable-scope/199436/7 "2020-03-05T06:33:05Z")

</div>

Is it possible to send your workflow file? Also name of the variable that you are facing issue with.

---

<div class="post-metadata">

**Author:** ![MadhuK](https://avatars.discourse-cdn.com/v4/letter/m/9f8e36/32.png) [@MadhuK](https://forum.uipath.com/u/MadhuK)\
**Post date:** [March 5, 2020, 5:30pm UTC](https://forum.uipath.com/t/variable-scope/199436/8 "2020-03-05T17:30:53Z")

</div>

Thank you. We resolved it.

---

<div class="post-metadata">

**Author:** ![Madhavi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/madhavi/32/18677_2.png) [@Madhavi](https://forum.uipath.com/u/Madhavi)\
**Post date:** [March 5, 2020, 11:17pm UTC](https://forum.uipath.com/t/variable-scope/199436/9 "2020-03-05T23:17:53Z")

</div>

What was the solution?

---

<div class="post-metadata">

**Author:** ![megharajky](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/megharajky/32/345216_2.png) [@megharajky](https://forum.uipath.com/u/megharajky)\
**Post date:** [May 16, 2020, 6:00am UTC](https://forum.uipath.com/t/variable-scope/199436/10 "2020-05-16T06:00:12Z")

</div>

In studio, check the workflow analyzer,  
Rule: [ST-NMG-005 - Variable Overrides Variable](https://docs.uipath.com/studio/lang-en/v2020.4/docs/st-nmg-005)

This will help you to find duplicate variables and resolve

---

<div class="post-metadata">

**Author:** ![raj.parsana](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/raj.parsana/32/152579_2.png) [@raj.parsana](https://forum.uipath.com/u/raj.parsana)\
**Post date:** [May 16, 2020, 9:23am UTC](https://forum.uipath.com/t/variable-scope/199436/11 "2020-05-16T09:23:21Z")

</div>

Hello @MadhuK,

Visit here,

> [@Mass move variable scope](https://forum.uipath.com/t/mass-move-variable-scope/138270):
>
> Hi Everyone! I am wondering if there is an easy way to move all variable scopes to their lowest level that they are currently used. I have a bad habit of putting most of them in the main scope because I’m not always sure if I will need them elsewhere. I know I need to break this habit, and will. But I’m wondering if there’s any built it way to do this to all variables. If not, it would be a super handy feature!!

---

<div class="post-metadata">

**Author:** ![MadhuK](https://avatars.discourse-cdn.com/v4/letter/m/9f8e36/32.png) [@MadhuK](https://forum.uipath.com/u/MadhuK)\
**Post date:** [May 19, 2020, 11:57pm UTC](https://forum.uipath.com/t/variable-scope/199436/12 "2020-05-19T23:57:23Z")

</div>

The issue was i had same variables hiding in different scope. Once i deleted the duplicate it was fixed.

---

<div class="post-metadata">

**Author:** ![raj.parsana](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/raj.parsana/32/152579_2.png) [@raj.parsana](https://forum.uipath.com/u/raj.parsana)\
**Post date:** [May 20, 2020, 4:46am UTC](https://forum.uipath.com/t/variable-scope/199436/13 "2020-05-20T04:46:57Z")

</div>

Okay 👍
