Capture Usernames

Hello,

I added a “Save” button that saves data from different Text Fields directly into a dataset created within a memory tag, but I want to capture the username or name and last name who does it. Is there a way to do this?

In Perspective each session will store session properties based on the user who logs in using the Project’s Identity Provider. So you can pull the username as well as the first/last names when a logged in user hits that save button from the session properties. Assuming that information is configured in the Identity Provider.

For example, in this screenshot I bound 3 labels to the corresponding session.props and logged in as the user Arthur:
image

But by doing that we’ll be assuming that we already know the person who is going to be doing that right? I wanted to see if I could just set a script to capture the user doing the modification regardless of who that person is. Does that make sense?

Perhaps this function within your script will satisfy your use case (Vision only sorry):

modifying_user = system.security.getUsername()

https://docs.inductiveautomation.com/display/DOC80/system.security.getUsername

The screenshot @kvane posted displayed the end result. You want something like this:

x = self.getSibling('TextField').props.text
y = self.getSibling('TextField_0').props.text
username = self.session.props.auth.user.username
# assuming a dataset with only three columns, where the final column is the username you are storing for each change.
system.dataset.addRow(startingDataset, len(startingDataset), [x, y, username])

system.security.getUsername() will NOT work for you as the scope is restricted to use in Vision clients.

Also, please note that if your project does not require authentication then there is every possibility that there might not be an authenticated user.

1 Like