# Navigation using a Momentary Button issue

**URL:** <https://forum.inductiveautomation.com/t/navigation-using-a-momentary-button-issue/8432>\
**Category:** Ignition\
**Created:** [May 10, 2014, 3:38pm UTC](https://forum.inductiveautomation.com/t/navigation-using-a-momentary-button-issue/8432 "2014-05-10T15:38:14Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [May 13, 2014, 5:55pm UTC](https://forum.inductiveautomation.com/t/navigation-using-a-momentary-button-issue/8432/21 "2014-05-13T17:55:47Z")

</div>

No. It sounds like the PLC writes nothing to the tag when a login fails. The best solution to this may be changing how the PLC writes to the tag as adamaustin has suggested.

You can use the script below. This script will check the value of event.source.currentUserLevel 2 seconds after the button is pressed. You may want to increase or decrease the delay.

```auto
def func(event=event):
	if event.source.currentUserLevel > 0:
		system.nav.swapTo("Window")
	else:
		system.gui.warningBox("Login Failed")		

if event.propertyName == "controlValue":
	if event.newValue == 1:
		system.util.invokeLater(func,2000)
```

---

<div class="post-metadata">

**Author:** ![oxanemi](https://avatars.discourse-cdn.com/v4/letter/o/0ea827/32.png) [@oxanemi](https://forum.inductiveautomation.com/u/oxanemi)\
**Post date:** [May 13, 2014, 6:05pm UTC](https://forum.inductiveautomation.com/t/navigation-using-a-momentary-button-issue/8432/22 "2014-05-13T18:05:50Z")

</div>

[quote=“nmudge”]No. It sounds like the PLC writes nothing to the tag when a login fails. The best solution to this may be changing how the PLC writes to the tag as adamaustin has suggested.

You can use the script below. This script will check the value of event.source.currentUserLevel 2 seconds after the button is pressed. You may want to increase or decrease the delay.

[code]  
def func(event=event):  
if event.source.currentUserLevel \> 0:  
system.nav.swapTo(“Window”)  
else:  
system.gui.warningBox(“Login Failed”)

if event.propertyName == “controlValue”:  
if event.newValue == 1:  
system.util.invokeLater(func,2000)  
[/code][/quote]

It says “Error running function from fpmi.system.invokeLater”. The error details:  
“NameError:Global name ‘system’ is not defined”

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [May 13, 2014, 6:08pm UTC](https://forum.inductiveautomation.com/t/navigation-using-a-momentary-button-issue/8432/23 "2014-05-13T18:08:43Z")

</div>

Try this:

```auto
def func(event=event):
   import system
   if event.source.currentUserLevel > 0:
      system.nav.swapTo("Window")
   else:
      system.gui.warningBox("Login Failed")      

if event.propertyName == "controlValue":
   if event.newValue == 1:
      system.util.invokeLater(func,2000)
```

---

<div class="post-metadata">

**Author:** ![oxanemi](https://avatars.discourse-cdn.com/v4/letter/o/0ea827/32.png) [@oxanemi](https://forum.inductiveautomation.com/u/oxanemi)\
**Post date:** [May 13, 2014, 6:18pm UTC](https://forum.inductiveautomation.com/t/navigation-using-a-momentary-button-issue/8432/24 "2014-05-13T18:18:06Z")

</div>

[quote=“nmudge”]Try this:

[code]  
def func(event=event):  
import system  
if event.source.currentUserLevel \> 0:  
system.nav.swapTo(“Window”)  
else:  
system.gui.warningBox(“Login Failed”)

if event.propertyName == “controlValue”:  
if event.newValue == 1:  
system.util.invokeLater(func,2000)  
[/code][/quote]

Whoa! That worked! Although when I press the the Logout PB on the same page, the warningBox reappears. But the Login button works to perfection!!

[Previous page](https://forum.inductiveautomation.com/t/navigation-using-a-momentary-button-issue/8432.md?page=1)
