Getting current user roles onStartup session

I am trying to populate a dropdown menu of all the roles that the current user belongs to after they have logged in to a Perspective session (using an internal usersource and Ignition default IdP). However, the function isn’t working. If I try to use system.user.getRoles(‘someUserSource’) instead, this does work and returns all the roles for the user source, so I know my dropdown works. And using‘hardcodedusername’,‘hardcodedpassword’,‘someUserSource’) also works. But I obviously can’t use that function since I don’t know what the password is for the user. I don’t even understand why this function requires the password if the password shouldn’t be known to anyone, not even the programmer.
Anyways, does anyone know what’s going on?

I think it has to do with script scope? The user manual shows has vision client scope
system.user.getRoles() has gateway and vision client scope.  

Completely forgot about scopes. Thanks for reminding me. However, I still can’t get anything to work to pull in the current user’s roles in Perspective. The session object has the roles under session.auth.user.roles, but it also doesn’t function properly.

You should actually be looking at the user object in the session properties; this removes the need to call out to the Gateway:
Screen Shot 2021-02-19 at 1.10.38PM

How so?


I forgot to type the “.props.” part. it is session.props.auth.user…I had tried session.auth.user…which didn’t work. Thanks. Growing pains of officially developing on Perspective for the first time