Log out button not working when first starting up project

After switching between pages 4-5 times it works. But at first it does not do anything. The page icon loads, the tags change because i see my component disappear. But it stays on the same page, like something stops it from switching. right it works after swapping a few times i have no ideas.

here is logout button code.

system.nav.swapTo('Logged Off')
system.security.switchUser("plc", "plc")
system.tag.writeToTag("[Client]BadgeSystem/DisplayCountdown", 0)
system.tag.writeToTag("[Client]BadgeSystem/TimerRunning", 0)
system.tag.writeToTag("[Client]BadgeSystem/TimerValue", 0)

im using 7.8.5

thank you , it is critical i figure this out.

Then you should contact support.

From the script you’ve provided I don’t see anything that would cause this not to work.

@lrose my company does not have a support contract which is why I am here.

Idk much about vision, and i doubt it rly matters for this but still. Avoid running code after navigating away. do the nav at the end.

@victordcq I tried moving the swap to the end but still get the same results.

i thought so:/

@victordcq its just so weird that it works perfectly after a few clicks then the occasional mess up.

I also do not see anything in the diagnostic window

I get this in my console log

SQLTagsClientProxy Removing Tags due to switching user.

any relation?

I adjusted the code, and it does not work for the time i.e. page to logout. then i go back to page and logout and it all works. very weird.

Try writing the tags first, then changing the user, then navigating.

Also, not familiar with 7.8, do you have a system.tag.writeAll()?

I would do the switch user last, and in a separate function via invokeLater.
Also consider using a single call to write all the tags synchronously.

@pturmel @lrose I do this is revised code, does not look to be writing to tags.

tags = ["[Client]BadgeSystem/DisplayCountdown", "[Client]BadgeSystem/TimerRunning", "[Client]BadgeSystem/TimerValue"]
values = [0, 0, 0]
def testwrite(tags, values)):
    system.tag.writeAll(tags,values)
system.util.invokeLater(testwrite)
system.nav.swapTo('Logged Off')
system.security.switchUser("plc", "plc")

i also tried

tags = ["[Client]BadgeSystem/DisplayCountdown", "[Client]BadgeSystem/TimerRunning", "[Client]BadgeSystem/TimerValue"]
values = [0, 0, 0]
def testwrite(tags, values):
	import system
    	system.tag.writeAll(tags,values)
system.util.invokeLater(testwrite)
system.nav.swapTo('Logged Off')
system.security.switchUser("plc", "plc")

Do this. And I see typos and wrong indentation.

@pturmel tags writing, still not swapping window though.

tags = ["[Client]BadgeSystem/DisplayCountdown", "[Client]BadgeSystem/TimerRunning", "[Client]BadgeSystem/TimerValue"]
values = [0, 0, 0]
system.tag.writeAll(tags,values)  
system.nav.swapTo('Logged Off')
def switcharu():
	import system
	system.security.switchUser("plc", "plc")
system.util.invokeLater(switcharu)

first time it does not, but if log back in to window then try to log out again it works.

Try a 1000 millisecond delay on the invokeLater.

@pturmel I added the delay and still not working. I see the loading refresh icon in the upper right corner but it stays on the same page even if i click 10 times. However I can swap between other windows no problem. just not the log out button one, very strange.

I am gonna try something i like dislike and adding the extra code in the other buttons. i’ll post back if it works.

@pturmel @lrose @victordcq
Thank you for all your help. The original code I posted works! As ugly as it may be.

The issue was the logged off page set to open on startup. Once I turned that off, duplicated that page, changed the name, set duplicated page to open on start up, it works perfectly now.

not sure why the open on startup would cause those issues. maybe a bug?