# Combing multiple rosters to a single roster

**URL:** <https://forum.inductiveautomation.com/t/combing-multiple-rosters-to-a-single-roster/71349>\
**Category:** Ignition\
**Created:** [March 20, 2023, 11:09pm UTC](https://forum.inductiveautomation.com/t/combing-multiple-rosters-to-a-single-roster/71349 "2023-03-20T23:09:14Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bharat\_Krishnan](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@Bharat\_Krishnan](https://forum.inductiveautomation.com/u/Bharat_Krishnan)\
**Post date:** [March 20, 2023, 11:09pm UTC](https://forum.inductiveautomation.com/t/combing-multiple-rosters-to-a-single-roster/71349/1 "2023-03-20T23:09:14Z")

</div>

Hi all, I am trying to create a roster which contains the users of three other rosters and i only require this new roster for a notification block. I am asked to make a notification pipeline for medium level alarms but different operators are to be called upon based on the machines. so I have to create 10 different rosters in total if I want to achieve this but i can do this if i am able to merge the existing rosters together and return the merged roster to the notification block. Is there any ways to do that ?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 21, 2023, 7:42am UTC](https://forum.inductiveautomation.com/t/combing-multiple-rosters-to-a-single-roster/71349/2 "2023-03-21T07:42:28Z")

</div>

You can dynamically produce any desired roster using a "calculated" roster. It is just a script that yields the contacts to use at that moment.

---

<div class="post-metadata">

**Author:** ![Bharat\_Krishnan](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@Bharat\_Krishnan](https://forum.inductiveautomation.com/u/Bharat_Krishnan)\
**Post date:** [March 21, 2023, 8:09pm UTC](https://forum.inductiveautomation.com/t/combing-multiple-rosters-to-a-single-roster/71349/3 "2023-03-21T20:09:10Z")

</div>

But I want to get the contacts from the roster so that in the future if i have to change a personnel I should only have to edit the roster. Is this possible with calculated roster?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 21, 2023, 8:59pm UTC](https://forum.inductiveautomation.com/t/combing-multiple-rosters-to-a-single-roster/71349/4 "2023-03-21T20:59:42Z")

</div>

[https://docs.inductiveautomation.com/display/DOC81/system.roster.getRosters](https://docs.inductiveautomation.com/display/DOC81/system.roster.getRosters)  
[https://docs.inductiveautomation.com/display/DOC81/system.roster.getRoster](https://docs.inductiveautomation.com/display/DOC81/system.roster.getRoster)

---

<div class="post-metadata">

**Author:** ![Bharat\_Krishnan](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@Bharat\_Krishnan](https://forum.inductiveautomation.com/u/Bharat_Krishnan)\
**Post date:** [March 21, 2023, 9:16pm UTC](https://forum.inductiveautomation.com/t/combing-multiple-rosters-to-a-single-roster/71349/5 "2023-03-21T21:16:27Z")

</div>

I tried using this system function but it still does not return the userlist. I am sharing the code that i used in the calculated roster as well :

 ![MergeRoster](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/0/1009d0e25860360d3d4d18397f9e7623457f2c6f.png)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 21, 2023, 10:15pm UTC](https://forum.inductiveautomation.com/t/combing-multiple-rosters-to-a-single-roster/71349/7 "2023-03-21T22:15:45Z")

</div>

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:

```python
[
  { "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](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:

```python
	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")

```

---

<div class="post-metadata">

**Author:** ![Bharat\_Krishnan](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@Bharat\_Krishnan](https://forum.inductiveautomation.com/u/Bharat_Krishnan)\
**Post date:** [March 21, 2023, 11:02pm UTC](https://forum.inductiveautomation.com/t/combing-multiple-rosters-to-a-single-roster/71349/8 "2023-03-21T23:02:18Z")

</div>

I tried this code like u said it returned an error in gateway log :

java.lang.ClassCastException: class java.lang.String cannot be cast to class java.util.List (java.lang.String and java.util.List are in module java.base of loader 'bootstrap')

```auto
def calculateRoster(event, builder):
	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
			]
		
	[userList] = mergeRosters(['TEST', 'TEST2'])
	return userList

```

```auto

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 21, 2023, 11:04pm UTC](https://forum.inductiveautomation.com/t/combing-multiple-rosters-to-a-single-roster/71349/9 "2023-03-21T23:04:16Z")

</div>

You're not calling it correctly. Look at the code I posted, and compare it to yours:

```auto
	[userList] = mergeRosters(['TEST', 'TEST2'])
	return userList

```

You're unnecessarily wrapping the return value in a list, and you're unnecessarily wrapping the input value to the function in a list.

---

<div class="post-metadata">

**Author:** ![Bharat\_Krishnan](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@Bharat\_Krishnan](https://forum.inductiveautomation.com/u/Bharat_Krishnan)\
**Post date:** [March 23, 2023, 12:02am UTC](https://forum.inductiveautomation.com/t/combing-multiple-rosters-to-a-single-roster/71349/10 "2023-03-23T00:02:07Z")

</div>

I made the corrections as u said and now the error displays :

> org.python.core.PyException: TypeError: getRoster(): 1st arg can't be coerced to String

```auto
def calculateRoster(event, builder):
	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
				]
			
	userList = mergeRosters("TEST", "TEST2")
	return userList

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 23, 2023, 1:32am UTC](https://forum.inductiveautomation.com/t/combing-multiple-rosters-to-a-single-roster/71349/11 "2023-03-23T01:32:45Z")

</div>

That's _still_ not the code I gave you; why are you wrapping rostername in curly braces? That's making a set.

---

<div class="post-metadata">

**Author:** ![Bharat\_Krishnan](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@Bharat\_Krishnan](https://forum.inductiveautomation.com/u/Bharat_Krishnan)\
**Post date:** [March 26, 2023, 8:51pm UTC](https://forum.inductiveautomation.com/t/combing-multiple-rosters-to-a-single-roster/71349/12 "2023-03-26T20:51:22Z")

</div>

Sorry about that, now when I take off the curly braces it seems to return an error like :

> java.lang.ClassCastException: class java.lang.String cannot be cast to class java.util.List (java.lang.String and java.util.List are in module java.base of loader 'bootstrap')

i have also posted the code i used again please do tell me if there is anything wrong with the script.

```auto
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("TEST", "TEST2")

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [March 27, 2023, 6:59am UTC](https://forum.inductiveautomation.com/t/combing-multiple-rosters-to-a-single-roster/71349/13 "2023-03-27T06:59:13Z")

</div>

Is the indentation like this in your script, or did the copy-paste mess it up ?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 27, 2023, 2:45pm UTC](https://forum.inductiveautomation.com/t/combing-multiple-rosters-to-a-single-roster/71349/14 "2023-03-27T14:45:13Z")

</div>

```python
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("TEST", "TEST2")

```

Think I was missing one set of square brackets, to put the contact infos into a list.

---

<div class="post-metadata">

**Author:** ![Bharat\_Krishnan](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@Bharat\_Krishnan](https://forum.inductiveautomation.com/u/Bharat_Krishnan)\
**Post date:** [March 27, 2023, 8:20pm UTC](https://forum.inductiveautomation.com/t/combing-multiple-rosters-to-a-single-roster/71349/15 "2023-03-27T20:20:17Z")

</div>

thank you the script now works and sends emails with the combined roster
