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.
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.
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.
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.