Change users roster by script

I’m trying to make an easy was to adjust what rosters a user is on. Currently we can use the built in roster template, and that works for now. But I would like to make it easier for the end users.

What I want to do is 3 things:

  1. Find out the current user
  2. Display all the rosters that user is in
  3. Be able to make changes and save back to the roster

Here’s the most basic example code example, without all the extra code connecting it to the display elements:

#In Perspective:
	#1. Get current user name (Doesn't work)
	# The call in Vision isn't available in Perspective
	# system.security.getUsername() 
	# Closest I can find, gets all users currently on system, but I can't tell who I am from the script
	system.perspective.getSessionInfo()

	#2. Display rosters (Works)
	rosters = system.roster.getRosters()

	#3. Save rosters (Works)
	system.roster.removeUsers(b, [user])
	system.roster.addUsers(b, [user])	

#In Vision:
	#1. Get current user name (Works)
	system.security.getUsername()
	
	#2. Display rosters (Works)
	rosters = system.alarm.getRosters()
	
	#3. Save rosters (Doesn't work)
	# System.roster is only available in Perspective, so these calls fail
	system.roster.removeUsers(b, [user])
	system.roster.addUsers(b, [user])	

I’ve searched through the API, and can’t tell if I’m just missing something, or it’s just not possible to do this way currently.

For Perspective, can’t you use the session properties to get the user name?

As for the vision side, I’m not sure that you will be able to do exactly what you described there. You can use the filterRoster extension function in the Roster Management object to show just the rosters the logged in user is in but I’m not sure if you’ll be able to custom script it with built in script function.

1 Like

Thank you! So, that solved my Perspective issues by adding this:

# Get username
self.session.props.auth.user.userName

I was looking for an API call, and hadn’t looked through the properties.