Hiding a component based on username

I have a client script which checks the logged in user and opens a window if the result is false.

name = system.security.getUsername()
if name != ‘test’ :
system.nav.openWindow(“Main Windows/Test”)

Next thing I want to do is check if the result is true and if it is, hide a date component on that window (Root Container.Date_1.visible property).

How do I add the second part of the check to the client script? How do I combine the windows name and the root cantainer…visible property and write a 0 or false in it?

name = system.security.getUsername()
if name != ‘test’ :
system.nav.openWindow(“Main Windows/Test”)
if name == ‘test’ :
???.visible = 0


Would an expression binding on the visible property accomplish what you want?

{[System]Client/User/Username} != 'test'

If it works it would indeed. I tried using system.security.getUsername() but that didn’t work in an expression. I’ll try this one tomorrow.

Is there a list where i can find all these variables? I tried searching but couldn’t find any.

And thanks!

Just use the Security Settings to Hide the component. Find more information on that in the documentation.

Component and Window Security Note: I am currently using 7.9 so this documentation is specific to that, newer version may have different information.

Also, in the Tag Browser there is a System folder which contains folders for different scopes and information.

There is also a Client folder which you and add tags to that become global to the project. (This is another way you can accomplish what you’re looking for)

1 Like

As @lrose notes, you can find these variables in the tag browser in the Designer:

Yes, scripting functions don’t work in expression bindings (and vice-versa). You can find all the expression functions in the manual as well as in the menu on the expression window:

Note that you can use the runScript expression to run a script in an expression binding, like this:

// Get username. Refresh every 250 ms.
runScript('system.security.getUsername()', 250)


That’s a lot of valuable info! I’ve only been using Ignition for 10 days now so pardon my “amateur” questions. I tend to get a lot of things done but sometimes I get stuck and this forum really helps!

1 Like