# Retargeting and Global Variables

**URL:** <https://forum.inductiveautomation.com/t/retargeting-and-global-variables/11787>\
**Category:** Ignition\
**Created:** [June 7, 2016, 2:10pm UTC](https://forum.inductiveautomation.com/t/retargeting-and-global-variables/11787 "2016-06-07T14:10:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kblankenship](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@kblankenship](https://forum.inductiveautomation.com/u/kblankenship)\
**Post date:** [June 7, 2016, 2:10pm UTC](https://forum.inductiveautomation.com/t/retargeting-and-global-variables/11787/1 "2016-06-07T14:10:56Z")

</div>

I am building an overview screen that multiple users could have open with “overview” templates in it. Each template will have a script that if clicked, will retarget the user to the master screen. The master screens are running on the shop floor without the overview.

My question is: I want a return button that will only appear if you have retargeted, so I was planning on passing “retargetOcurred” and “hostName” to the project when I retarget as globals. But if two people retarget to the same screen at similar times, will the globals be overwritten or will they be client scoped?

Could I fix this by using a client tag that gets written to when the client launches or how would I best be able to do this?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 7, 2016, 2:36pm UTC](https://forum.inductiveautomation.com/t/retargeting-and-global-variables/11787/2 "2016-06-07T14:36:12Z")

</div>

Global variable aren’t really global – they are per-client. If you look at the documentation for [system.util.retarget()](https://docs.inductiveautomation.com/display/DOC/system.util.retarget), you’ll see that it provides a pair of globals for you that might be all you need. 🙂

---

<div class="post-metadata">

**Author:** ![kblankenship](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@kblankenship](https://forum.inductiveautomation.com/u/kblankenship)\
**Post date:** [June 14, 2016, 12:20pm UTC](https://forum.inductiveautomation.com/t/retargeting-and-global-variables/11787/3 "2016-06-14T12:20:32Z")

</div>

Thank you for the quick reply pturmel. ![:prayer:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/e5a7e3b63facc151ea73e3b45db7bdb3d4bdc316.gif ":prayer:") I could not find the per-client documentation anywhere.

I saw that these pass the two variables, but I wanted to make sure that would impact and other running clients.

My next question on this is I would like build a script that checks if those variables exist, however I cannot seem to get it right. I am using system.util.getGlobals() and it returns what looks like a python dictionary, but when I try to use something like “.has\_Key(’\_RETARGET\_FROM\_PROJECT’)”, I get an error saying this is a “stringmap” and does not have an attribute call has\_Key. Is there a way I can check if the variable is active without getting an error like this?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 14, 2016, 1:41pm UTC](https://forum.inductiveautomation.com/t/retargeting-and-global-variables/11787/4 "2016-06-14T13:41:32Z")

</div>

Interesting. So it’s really a java [Map](http://docs.oracle.com/javase/8/docs/api/java/util/Map.html), not a true python dictionary. So the .containsKey() method would be appropriate. However, jython is generally good at making java Maps look like dictionaries. Have you tried the more pythonish:[code]g = system.util.getGlobals()  
if ‘\_RETARGET\_FROM\_PROJECT’ in g:

# do something[/code]Also try listing the contents:[code]for k, v in g:

print k, v[/code]

---

<div class="post-metadata">

**Author:** ![kblankenship](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@kblankenship](https://forum.inductiveautomation.com/u/kblankenship)\
**Post date:** [June 14, 2016, 1:44pm UTC](https://forum.inductiveautomation.com/t/retargeting-and-global-variables/11787/5 "2016-06-14T13:44:45Z")

</div>

I think I finally found it:

Looks like if you do

```auto
g = dict(system.util.getGlobals())
```

it will convert it into a callable dictionary.

I was then able to check

`if '_RETARGET_FROM_PROJECT' in g:
   #do something here
`

I did originally try your suggestion with the “if - in” and I got an error that stringmap was not callable but this looks like it is completing the conversion. Thank you for your help.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 14, 2016, 1:55pm UTC](https://forum.inductiveautomation.com/t/retargeting-and-global-variables/11787/6 "2016-06-14T13:55:09Z")

</div>

Very good.  
BTW, the online manual does have some discussion of python scope in the [script console](https://docs.inductiveautomation.com/display/DOC/Scripting+Console) and [advanced scripting](https://docs.inductiveautomation.com/display/DOC/Gateway+vs.+Client+Event+Scripts) sections.
