Combing multiple rosters to a single roster

Your code has a lot of problems.

Chiefly:

  1. You're not returning the contact infos as a list of possible contact infos
  2. You're not differentiating between SMS, email, or phone numbers, which you would want to do.
  3. You don't need to call system.user.getUser if you use system.roster.getRoster(), which directly returns User objects
  4. Hardcoding in default to the system.user.getUser function is also a bad idea.
  5. You're returning in the wrong format anyways: you're returning something like:
[
  { "Maintenance Roster": [
    { "joe": [contactInfo] }
    ]
  }
]

But you need to return a direct list of user-like objects; see the manual:
https://docs.inductiveautomation.com/display/DOC81/Notification+Block#NotificationBlock-Calculated

A generic mergeRosters suitable for use in a calculated roster script would be something like this:

	def mergeRosters(*rosterNames):
		return [
		    dict(username = user.get(user.Username), **{ci.contactType: ci.value for ci in user.contactInfo})
			for rosterName in rosterNames
			for user in system.roster.getRoster(rosterName).users
		]
	
	return mergeRosters("day shift", "night shift")
1 Like