# \[bug-15735\]system.gui.getScreenIndex() returns wrong Index

**URL:** <https://forum.inductiveautomation.com/t/bug-15735-system-gui-getscreenindex-returns-wrong-index/31024>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [January 2, 2020, 9:24pm UTC](https://forum.inductiveautomation.com/t/bug-15735-system-gui-getscreenindex-returns-wrong-index/31024 "2020-01-02T21:24:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [January 2, 2020, 9:24pm UTC](https://forum.inductiveautomation.com/t/bug-15735-system-gui-getscreenindex-returns-wrong-index/31024/1 "2020-01-02T21:24:51Z")

</div>

So this is a strange one.

We have a multi-monitor system that I’m using system.gui.getScreenIndex to get the screen index that the operator clicks on to properly show popups etc at the location of the mouse.

> **Old post**
>
> This all works fine, until I’m two functions deep.
> 
> Suppose I have two functions:
> 
> ```auto
> def functionA():
> Do stuff to figure out which popup to show etc...
> Call functionB
> 
> ```
> 
> ```auto
> def functionB():
> Do stuff to position the popup
> 
> ```
> 
> On the template I call functionA to determine the popup, which in turn calls functionB to position the popup.
> 
> If I have a button that calls functionA on a window that I know is screenIndex 1 and check system.gui.screenIndex it returns a 1. However if functionA then calls functionB and I check system.gui.screenIndex it returns a 0. Now… if I just straight up call functionB from the window it properly returns system.gui.screenIndex then 1 is returned not 0.
> 
> Any idea why? I can get around it in my code… I just wanted to bring this up and see if this is a known issue or not.

OK… so after more testing it isn’t the embedded function calling.

After I issue a system.nav.openWindowInstance the screen index is reset to 0. This occurs even when I specifically enumerate the desktop to open the window on with either the screen index or the desktop handle using system.nav.desktop(handle).openWindowInstance.

Any reason this is happening? I’ve got a work around… I just save the screen index before calling openWindowInstance but this seems to not be working as intended.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [January 2, 2020, 10:36pm UTC](https://forum.inductiveautomation.com/t/bug-15735-system-gui-getscreenindex-returns-wrong-index/31024/2 "2020-01-02T22:36:24Z")

</div>

I ran a test on two monitors, with a window and a button with the following code:

```auto
def functionA():
    print system.gui.getCurrentDesktop()
    functionB()
    
def functionB():
    print system.gui.getCurrentDesktop()
    
functionA()

```

and received the correct results…

```auto
Monitor 1
Monitor 1
primary
primary

```

Running v7.9.12

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [January 2, 2020, 11:02pm UTC](https://forum.inductiveautomation.com/t/bug-15735-system-gui-getscreenindex-returns-wrong-index/31024/3 "2020-01-02T23:02:00Z")

</div>

Yeah… I did further testing and edited the original post.

It seems to be system.nav.openWindowInstance that is giving me fits.

And this is on 8.0.6 with a new function for screen handles.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [January 3, 2020, 12:34am UTC](https://forum.inductiveautomation.com/t/bug-15735-system-gui-getscreenindex-returns-wrong-index/31024/4 "2020-01-03T00:34:32Z")

</div>

For what it’s worth, I tested on 8.0.7 and received the same results as 7.9.12

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [January 3, 2020, 1:37pm UTC](https://forum.inductiveautomation.com/t/bug-15735-system-gui-getscreenindex-returns-wrong-index/31024/5 "2020-01-03T13:37:58Z")

</div>

This is the code I’m using to test.

```auto
window = 'Popups/Batch Plant/Edit/Ingredient'
print 'Index Position 1: %d' %(system.gui.getScreenIndex()) //Produces 1 as expected
system.nav.openWindowInstance(window)
print 'Index Position 2: %d' %(system.gui.getScreenIndex()) //Produces 0

```

@jlandwerlen can you test on yours? The window isn’t specific… can be any popup.

Thanks!

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [January 3, 2020, 2:02pm UTC](https://forum.inductiveautomation.com/t/bug-15735-system-gui-getscreenindex-returns-wrong-index/31024/6 "2020-01-03T14:02:48Z")

</div>

Confirmed. If I run the code you attached, only substituting the window path, it will behave just as you described.

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [January 3, 2020, 2:08pm UTC](https://forum.inductiveautomation.com/t/bug-15735-system-gui-getscreenindex-returns-wrong-index/31024/7 "2020-01-03T14:08:53Z")

</div>

OK that’s good I guess… 😃 at least I know it isn’t me causing issues.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 3, 2020, 4:36pm UTC](https://forum.inductiveautomation.com/t/bug-15735-system-gui-getscreenindex-returns-wrong-index/31024/8 "2020-01-03T16:36:20Z")

</div>

Hmm, I can see why you’d want `getScreenIndex()` to work this way, but I’m not sure if it’s possible with our current implementation…I’ll file a bug ticket.

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [January 3, 2020, 5:43pm UTC](https://forum.inductiveautomation.com/t/bug-15735-system-gui-getscreenindex-returns-wrong-index/31024/9 "2020-01-03T17:43:06Z")

</div>

Thanks Paul.

If you guys need me to test anything etc… just hit me up.
