How to get logged in userName in project script library

Hi,

I am trying to get logged In username in script library function by using “system.security.getUsername()“

But it is showing error , ‘Object has no attribute getUsername‘.

whats wrong here, any other way to get the username in script library?

Thanks!!!

Script library isn't a scope where scripts execute, it's just a place where they are written and stored for re-use by other parts of Ignition.

You are probably trying to call this script from somewhere in the Gateway (tag event, etc...), or from Perspective, which is also Gateway-scoped, and this function only works in a Vision Client.

yes I am calling this script in gateway event on tag change script.

any way to get the username in gateway tag change Script or project library script?

There is no username. Gateway stuff isn't associated with a user.

1 Like

Think about it like this. Say you had 10 vision or perspective clients open all with different users logged in. A gateway tag (which lives in the gateway scope) triggers a gateway tag change event. What “user” would be associated with it anyways? Also consider that you could have no clients open, and the gateway tag change event would still trigger - certainly no user now.

Why don’t you explain what you are actually trying to do, what your use case is?

In script library I have one insert query , when logged in users clicked on save one tag is updating on tag change I am calling this insert query script.

In this query I want to store username in DB ,who is changing or saving the record.

for that I want logged in username in script.

This is the use case.

So it’s on a button press then? That is your trigger to save the tag, not a tag change event?

No, On button start production is getting started and when it starts there and multiple status we are getting from PLC in tags, when I am getting the status ‘complete’ in tag then this script getting triggered.

Not from button directly.

Use the button to get the user information. Save it to log it later, or log it immediately. That is in the scope you need to get authentication data.

2 Likes

Log the username separately when the user presses the button. The tag change doesn't know what action triggered the chain of events which led to the tag change.

The only other way I can think of is to write the username to a tag specific for that application, "SaveButtonLastUsername" and log that when the batch is complete. This could be a problem if multiple users press the button from different clients.

1 Like

okay, I will try this.

Thanks!!!