# 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:** 20\
**Page:** 1

<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 10, 2014, 3:38pm UTC](https://forum.inductiveautomation.com/t/navigation-using-a-momentary-button-issue/8432/1 "2014-05-10T15:38:14Z")

</div>

I’m using a Momentary button for Logging In. The controlValue is derived from a tag from the PLC which is a Pushbutton.

I want it to navigate to another window after it is pressed and after it checks the value of another property (which is a tag). I wrote a script in actionperformed but it doesn’t work (It logs in but doesn’t navigate)

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

Your help is appreciated! Thank You!

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [May 12, 2014, 1:23pm UTC](https://forum.inductiveautomation.com/t/navigation-using-a-momentary-button-issue/8432/2 "2014-05-12T13:23:23Z")

</div>

This might be a silly question but you do have a window named “Window”? did you try without permissions and see if the warning box pops up?

---

<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 12, 2014, 2:14pm UTC](https://forum.inductiveautomation.com/t/navigation-using-a-momentary-button-issue/8432/3 "2014-05-12T14:14:19Z")

</div>

If “Window” does exist is it in any folders? If so the full path to the window needs to be provided.

Are you getting any error?

Best,  
Nick Mudge  
Ignition Consultant  
[nickmudge.info](http://nickmudge.info)

---

<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 12, 2014, 6:10pm UTC](https://forum.inductiveautomation.com/t/navigation-using-a-momentary-button-issue/8432/4 "2014-05-12T18:10:23Z")

</div>

> [@drewdin](#):
>
> This might be a silly question but you do have a window named "Window"? did you try without permissions and see if the warning box pops up?

No, I do not.  
There are no permissions currently in any of those windows! The warning box pops up even if the conditions in the if statement are satisfied. I'm guessing its a timing issue and its reading the values from the PLC even before the PLC is able to edit them.

I made it to work by binding the tag values to the Root Container and made a script in propertyChange of the Root Container. So, whenever any property of the Root Container changes, it automatically navigates to the "Window" screen.

It worked alright but my boss needs a simpler solution so that he can get a better understanding of how it works!

---

<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 12, 2014, 6:11pm UTC](https://forum.inductiveautomation.com/t/navigation-using-a-momentary-button-issue/8432/5 "2014-05-12T18:11:44Z")

</div>

[quote=“nmudge”]If “Window” does exist is it in any folders? If so the full path to the window needs to be provided.

Are you getting any error?

Best,  
Nick Mudge  
Ignition Consultant  
[nickmudge.info](http://nickmudge.info)[/quote]

No, It is not inside any folder.  
The warning box pops up all the time and there are no errors in the script.

---

<div class="post-metadata">

**Author:** ![adamaustin](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@adamaustin](https://forum.inductiveautomation.com/u/adamaustin)\
**Post date:** [May 12, 2014, 8:11pm UTC](https://forum.inductiveautomation.com/t/navigation-using-a-momentary-button-issue/8432/6 "2014-05-12T20:11:36Z")

</div>

This probably means that whatever you are using to populate the currentUserLevel is not working. You should post the code for the binding or whatever scripting you are trying to use to populate that value.

---

<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, 1:40am UTC](https://forum.inductiveautomation.com/t/navigation-using-a-momentary-button-issue/8432/7 "2014-05-13T01:40:30Z")

</div>

The CurrentUserLevel automatically gets changed by the PLC once the Login Pushbutton is pressed(once the controlValue becomes 1). The problem, however, is that the script is running before the CurrentUserLevel is edited by the PLC, thus the error! I tried using the time.sleep function but to no avail.

Is there a way where we can let the button perform its action (set controlValue to 1) first and then wait a couple of seconds and then check the if statement?

---

<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, 2:47am UTC](https://forum.inductiveautomation.com/t/navigation-using-a-momentary-button-issue/8432/8 "2014-05-13T02:47:15Z")

</div>

Use system.util.invokeLater. The second argument takes a delay in milliseconds.

Manual entry:  
[inductiveautomation.com/support/ … elater.htm](http://inductiveautomation.com/support/usermanuals/ignition/index.html?system_util_invokelater.htm)

Best,  
Nick Mudge  
Ignition Consultant  
[nickmudge.info/](http://nickmudge.info/)

---

<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, 4:02am UTC](https://forum.inductiveautomation.com/t/navigation-using-a-momentary-button-issue/8432/9 "2014-05-13T04:02:36Z")

</div>

Would this work:

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

---

<div class="post-metadata">

**Author:** ![adamaustin](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@adamaustin](https://forum.inductiveautomation.com/u/adamaustin)\
**Post date:** [May 13, 2014, 2:41pm UTC](https://forum.inductiveautomation.com/t/navigation-using-a-momentary-button-issue/8432/10 "2014-05-13T14:41:59Z")

</div>

That looks good, Nick. That code would go in the propertyChange event of the Root Container (for oxanemi’s info). There would be no code in the momentary button and when the PLC code finally changed the custom property, then this code would go be affected. Very good.

---

<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, 3:43pm UTC](https://forum.inductiveautomation.com/t/navigation-using-a-momentary-button-issue/8432/11 "2014-05-13T15:43:19Z")

</div>

[quote=“nmudge”]Would this work:

`
if event.propertyName == "currentUserLevel":
	if event.newValue > 0:
		system.nav.swapTo("Window")
	else:
		system.gui.warningBox("Login Failed")
`[/quote]

It worked for the navigation part well! But when the login fails, it doesnt show up the warning box!

The initial value of currentUserLevel is 0 and it stays the same when a login fails. I tried using this code but to no avail.

```auto
if controlValue==1:
    if event.propertyName == "currentUserLevel":
	    if event.newValue > 0:
		    system.nav.swapTo("Window")
	    elif event.newValue==event.oldValue:
		    system.gui.warningBox("Login Failed")
```

I tried using it without the first if statement and it still did not return a warning!

---

<div class="post-metadata">

**Author:** ![adamaustin](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@adamaustin](https://forum.inductiveautomation.com/u/adamaustin)\
**Post date:** [May 13, 2014, 4:04pm UTC](https://forum.inductiveautomation.com/t/navigation-using-a-momentary-button-issue/8432/12 "2014-05-13T16:04:21Z")

</div>

You could try setting the currentUserLevel to negative one (-1) when a login fails and then set it back to zero (0) after the system message pops up. Of course, you’ll have to update your code to look for -1.

---

<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, 4:05pm UTC](https://forum.inductiveautomation.com/t/navigation-using-a-momentary-button-issue/8432/13 "2014-05-13T16:05:07Z")

</div>

I put the script in propertyChange. Since there isn’t any property change, that else statement isn’t executing. Is there a workaround?

---

<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, 4:39pm UTC](https://forum.inductiveautomation.com/t/navigation-using-a-momentary-button-issue/8432/14 "2014-05-13T16:39:23Z")

</div>

> [@adamaustin](#):
>
> You could try setting the currentUserLevel to negative one (-1) when a login fails and then set it back to zero (0) after the system message pops up. Of course, you'll have to update your code to look for -1.

I don't know much about PLC's but my boss thinks doing that may fault it.

---

<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, 4:41pm UTC](https://forum.inductiveautomation.com/t/navigation-using-a-momentary-button-issue/8432/15 "2014-05-13T16:41:36Z")

</div>

> [@adamaustin](#):
>
> You could try setting the currentUserLevel to negative one (-1) when a login fails and then set it back to zero (0) after the system message pops up. Of course, you'll have to update your code to look for -1.

Well, Incase he agrees. Where do I write the code for it? In the mousebutton pressed events?

---

<div class="post-metadata">

**Author:** ![adamaustin](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@adamaustin](https://forum.inductiveautomation.com/u/adamaustin)\
**Post date:** [May 13, 2014, 5:01pm UTC](https://forum.inductiveautomation.com/t/navigation-using-a-momentary-button-issue/8432/16 "2014-05-13T17:01:32Z")

</div>

You would change it in the PLC. There are an infinite number of ways of solving this. Look into trying to use [client tags](http://inductiveautomation.com/support/usermanuals/ignition/types_of_sqltags.htm) to figure out if the button was pressed.

---

<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:12pm UTC](https://forum.inductiveautomation.com/t/navigation-using-a-momentary-button-issue/8432/17 "2014-05-13T17:12:29Z")

</div>

When a login fails does the PLC set event.source.currentUserLevel to 0?  
If so then you can use the script below. Put it on the propertyChange event on the button.  
This script does not require changing the PLC.

```auto
if event.propertyName == "controlValue":		
	if event.newValue == 1:
		event.source.currentUserLevel = -1

if event.propertyName == "currentUserLevel":		
	if event.newValue > 0:
		system.nav.swapTo("Window")
	elif event.newValue == 0:
		system.gui.warningBox("Login Failed")
```

Nick Mudge  
Ignition Consultant  
[nickmudge.info](http://nickmudge.info)

---

<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, 5:18pm UTC](https://forum.inductiveautomation.com/t/navigation-using-a-momentary-button-issue/8432/18 "2014-05-13T17:18:32Z")

</div>

[quote=“nmudge”]When a login fails does the PLC set event.source.currentUserLevel to 0?  
If so then you can use the script below. Put it on the propertyChange event on the button.  
This script does not require changing the PLC.

```auto
if event.propertyName == "controlValue":		
	if event.newValue == 1:
		event.source.currentUserLevel = -1

if event.propertyName == "currentUserLevel":		
	if event.newValue > 0:
		system.nav.swapTo("Window")
	elif event.newValue == 0:
		system.gui.warningBox("Login Failed")
```

Nick Mudge  
Ignition Consultant  
[nickmudge.info](http://nickmudge.info)[/quote]

No, the Initial value of currentUserLevel is 0 and it stays 0 if the login fails. If the login is successful, only then the value changes!

---

<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:27pm UTC](https://forum.inductiveautomation.com/t/navigation-using-a-momentary-button-issue/8432/19 "2014-05-13T17:27:05Z")

</div>

Okay. Please try the script anyway as it may still work.

---

<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, 5:42pm UTC](https://forum.inductiveautomation.com/t/navigation-using-a-momentary-button-issue/8432/20 "2014-05-13T17:42:30Z")

</div>

Still no warning box even though its setting the currentUserLevel property to -1! Do I need to make the currentUserLevel property bi-directional?

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