Access user attributes from BasicUser object

My goal is to show the list of users that belongs to a specific Roster.

I tried the following code but i got stuck and i don't know how to continue:

#Get the roster
roster = system.roster.getRoster(self.view.params.roster_name)
for user_ref in roster.getUsers():
   username = user_ref.get('username') 

it throws the following error:

TypeError: get(): 1st arg can't be coerced to com.inductiveautomation.ignition.common.config.Property

Here's some information i found:

  • roster.getUsers() returns a list of BasicUser objects
  • print(str(user_ref)) => {badge=null, schedule=Always, firstname=Luca, notes=null, language=it_IT, user.pin=, username=Elettricista1, lastname=Rossi}
  • user_ref.Username = username

What i expect is to find a way to retrieve this damn username.

Big thanks to anyone throwing some help my way!

Try:
user_ref.get(user_ref.Username)

It works!
Thank you very much Paul

I feel this should be mentioned in the user manual, as it took a relatively long time for me to give up hunting through, first the user manual, then the javadocs, trying all sorts of things, then eventually giving up and searching here to find this, which works, but it not obvious in the slightest (and I've used Ignition once or twice before)

The whole user stuff is convoluted. Went thru the same bundle of fun trying to figure it out. Would be great to see some improved docs.

FWIW, there is a "centralized" reference here:

The whole situation is unnecessarily complicated by some legacy debt.
If you have an explicitly wrapped PyUser, user.get("username") works - and all the system.user scripting functions should return PyUser objects. But if you somehow end up with something that's not a PyUser, you have to do the awkward reference thing. And it wouldn't surprise me if there are code paths that don't properly hand back a PyUser still, because we're not doing that wrapping automatically.

One thing we could/should do is add constants, now that the hinting system supports them - at least then you'll have some autocomplete for our known attributes, so

user = system.user.getUser("someuser")
username = user.get(system.user.Username)

Or something to that effect.