runScript on Client Event Scripts -> Startup

Hi,

I’m trying to run a security script on Client Event Scripts -> Startup for a specific user that will grant the user to open only the specified windows in the project, but it’s not working.
Code below:

script name: project.Security

def clearance():
name = system.security.getUsername()
if name == ‘john’:
system.nav.openWindow(“Main Window”)
system.nav.openWindow(“SEAU Sighet”)
else:
(“You don’t have the permission to access the page!!”)

On Client Event Scripts -> Startup:
runScript(“project.Security”)

Any idea, please?

Thank you.

in the startup script you call the other script, you don’t use runscript.

project.Security.clearance()

Also note that shared and project scripts are modules, not simple scripts. Modules are imported by the script manager, running just once, and the functions and variables defined within persist until the script is edited and therefore reloaded. Trying to execute “project.Security” is automatically a mistake. Execution must always have the form “project.someModule.someFunction()”. (Variables and bare callables would omit the parens, of course.)

I tried the code below and it runs ok in the Script console, but it’s not opening the requested page when logging in.
Is it because I have a main window activated that opens when logging in ?

def clearance():
name = system.tag.getTagValue("[System]Client/User/Username")
if name == ‘admin’:
system.nav.openWindow(‘Old Sensors’)
else:
system.gui.errorBox(‘You don’t have access to this window!!’)

In Startup: project.Security.clearance()

The normal function to return a tag value is:

name = system.tag.read("[System]Client/User/Username").value

or as you did above to get the currently logged in user:

name = system.security.getUsername()

Both should return the Username logged in to the client. However, when you run this script in the Script console, it will return the name of the user logged in to the Designer. Are you sure that ‘admin’ is logged in to the client when it runs this on start-up?