# How to save a local variable (test case variable) as a global variable so that it can be used in another test case?

**URL:** <https://forum.katalon.com/t/how-to-save-a-local-variable-test-case-variable-as-a-global-variable-so-that-it-can-be-used-in-another-test-case/83934>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [February 2, 2023, 1:44pm UTC](https://forum.katalon.com/t/how-to-save-a-local-variable-test-case-variable-as-a-global-variable-so-that-it-can-be-used-in-another-test-case/83934 "2023-02-02T13:44:12Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![anon46315158](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@anon46315158](https://forum.katalon.com/u/anon46315158)\
**Post date:** [February 6, 2023, 9:49am UTC](https://forum.katalon.com/t/how-to-save-a-local-variable-test-case-variable-as-a-global-variable-so-that-it-can-be-used-in-another-test-case/83934/14 "2023-02-06T09:49:50Z")

</div>

> [@mwarren04011990](#):
>
> IMHO, `GlobalVariables` should be used for configuration data.

Few more thoughts on this.  
I am not sure what the concerns are. I suppose here, @mwarren04011990 won’t like the execution profiles to be ‘polluted’ with unneeded variables.  
Few solutions here.  
Understanding how GlobalVariable works, we can put ‘irelevant’ variables in the `default` profile. There is no need to have a real default value, just to exist and be declared with the right type.  
Relevant configuration data for the environment subject to test (staging, production etc) can be stored in the associated execution profile.  
So, we segregate the configuration data from the shared data variables.

If this is also disliked, the GlobalVariables for data-sharing can be added ‘on-the-fly’ so will never be shown in the UI (Katalon never writes back such during/after the execution, like Postman do).  
We simply extend the funtionality of GlobalVariables class to use it also as a container for temporary data.  
An example of how this can be achieved is here:

> [@How to pass user defined parameters from command line](http://forum.katalon.com/t/how-to-pass-user-defined-parameters-from-command-line/8771/22):
>
> You can also define environment variable (with path to external configuration or properties file) in the session will be used to execute Katalon studio and then in the TestListener read the value of variable (path to the file), load that file and override settings for project, Global variables etc. To create new GlobalVariable I used metaprogramming: void addGlobalVariable(String name, def value) { MetaClass mc = script.evaluate("internal.GlobalVariable").metaClass String getterName = "…

---

_[View the full topic](https://forum.katalon.com/t/how-to-save-a-local-variable-test-case-variable-as-a-global-variable-so-that-it-can-be-used-in-another-test-case/83934)._
