Get users usersource when using system.alarm.getRosters()

Hello everyone,

I am currently utilizing a Teltonika device and its API to send alarm SMS messages. Specifically, I am using the system.alarm.getRosters() function to retrieve a list of users associated with a specific roster, along with their contact details.

However, I have encountered a challenge: rosters can consist of users from various sources, and when I access the roster information, it does not indicate which user source each user was added from. As a result, I am forced to use a static user source when retrieving contact information, rather than being able to programmatically access this metadata within my script.

This limitation complicates the setup of rosters that include users from different sources. Is there a way to obtain this user source information programmatically?

It's undocumented and only works in Gateway scope, but I think you can call system.alarm.getRoster(rosterName) to get a RosterModel object, which has actual User objects in it (RosterModel::getUsers()), which should include profile and contact info.

2 Likes

Got it working, thanks.

def test():
	logger=system.util.getLogger('api_test')
	ros='ROS_Test'
	roster = system.alarm.getRoster(ros)
	for user_object in roster.getUsers():
		contacts= user_object.getContactInfo()
		for contact in contacts:
			if contact.contactType=='sms' or contact.contactType=='phone':
				number=contact.getValue()
				logger.info(str(number))
	return 

system.roster.getRoster does the same operation and is supported:

I don't remember the rationale for having system.alarm and system.roster functions :man_shrugging:

2 Likes

Something weird is happening there , when I try and get the user notes it doesn't work?

I can see the notes data in the getRawValueMap() but not matter what I do cannot access it typecasting to python dictionary or using the get() method?

		# get the roster model for using the roster name
		roster = system.alarm.getRoster(roster)
		# get the users found in the roster model
		users= roster.getUsers()
		# array for storing the numbers
		roster_numbers=[]
		# loop throught each user model found in the roster model
		for user_object in users:
			# extract the users contact information
			
			notes= user_object.get("notes")

Try:

notes = user_object.get(user_object.Notes)

When it's not a "PyUser", for complicated/hard to explain reasons, you have to use specific accessor fields as the 'keys' to get().

That worked thanks.

I am trying to update the user notes via scripting but the .set() method doesn't seem to work.

Here is the code script im using

user = system.user.getUser("default", "liam")
user.set('Notes','test')
system.user.editUser("default", user)

I also tried using the .set(user.Notes,'test') but this also doesn't work.

It would definitely be this form, just like accessing the property. If you make other edits, are those applied? Any errors in the gateway logs, or on the UIResponse object you get back?

I get a UIReponise object back , but when I go into the user profile on the gateway I don't see any changes.

Should I check the information contained in the UIResponse object?

Yes, examine the UI Response for info, errors, and warns:
https://files.inductiveautomation.com/sdk/javadoc/ignition80/8.0.12/com/inductiveautomation/ignition/common/messages/UIResponse.html

1 Like

Okay found the error [You are not authorized to modify the Gateway system user source.]
Is there a setting in the gateway to allow this to be done via scripting?

Found the setting from this thread