If else swap to

I want to login then swap screen, if user does not have access go to access denied page

here is my code. it will log on, but will not swap the window

# This script was generated automatically by the navigation
# script builder. You may modify this script, but if you do,
# you will not be able to use the navigation builder to update
# this script without overwriting your changes.

password = system.gui.passwordBox("Scan Badge")

system.nav.openWindow("Main Windows/TableImport")
window = system.gui.getWindow("Main Windows/TableImport")
data = window.rootContainer.getComponent("User Table").data
system.nav.closeWindow("Main Windows/TableImport")
user_name = ""
access_lvl = ""

for row in range(data.rowCount):
	index_row = data.getValueAt(row, 3)
	if index_row == password:
		user_name = data.getValueAt(row, 1)
        access_lvl = data.getValueAt(row, 2)
		break

#Disables Read-Only-Mode, starts timer
if access_lvl is "LVL_2" or access_lvl is "LVL_4":
    system.nav.swapTo('Powder Main')
    system.util.setConnectionMode(3)
    system.tag.writeToTag("System1/Project1/ReadModeOnly", 0)
    system.tag.writeToTag("System1/Project1/TimerState", 1)
    else
    system.nav.swapTo('Access Denied')
	
success = system.security.switchUser(user_name, password)

# If the login didn't work, give input focus back to the
# username component, so that the user can try again
if not success:
	system.tag.writeToTag("System1/Project1/ReadModeOnly", 1)
	system.tag.writeToTag("System1/Project1/TimerState", 0)
	system.nav.openWindow("Nav")
	window = system.gui.getWindow("Nav")
	window.rootContainer.getComponent("Timer").value = value


Is this part a copy paste to forum error? ( The else)

If the ‘else’ indintation is a copy paste error, then I suspect you’re getting an error at this line. system.tag.writeToTag() doesn’t exist. It should be system.tag.writeBlocking() the function requires you to provide a list of tag paths and a list of values.

system.tag.writeBlocking(['System1/Project1/ReadModeOnly'],[0])

through some research i found the level accesss has to be written as below

if u'Administrator' in roles or u'LVL_2' in roles or u'LVL_4' in roles:
	system.nav.swapTo('Powder Main')
else:
	system.nav.swapTo('Access Denied')