Cannot get user name and role name in Global Script Library

Ignition version 7.9.4
I want to get client user , role ,IP address then insert these information to database when tag value change.
So I write a script in Global Script Library and call it in tag value change event:
user = system.security.getUsername()
role = system.security.getRoles()
clientIP = system.tag.read("[System]Client/Network/IPAddress").value

But I get a error message in Tag Diagnostic:
AttributeError: ‘com.inductiveautomation.ignition.common.script.Imm’ object has no attribute ‘getRoles’

And the IP address inserted into database displayed as “None”.

You can only get the username and roles when your script is executing in the scope of a client.

A tag value change script executes on the gateway and has no user associated with it.

1 Like

Thanks for reply!
Why the IP address inserted to database displayed as “None”, even if I write the IP address to an memory string tag it also be “None”?

Because the tag you’re trying to read ([System]Client/Network/IPAddress) doesn’t have a value in the gateway scope where you’re reading it from. If you want the current system’s address in a way that works on all scopes, then you should use either system.net.getIPAddress or system.net.getExternalIpAddress.