# Filtering Roster based on User Role

**URL:** <https://forum.inductiveautomation.com/t/filtering-roster-based-on-user-role/96252>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [September 20, 2024, 7:30pm UTC](https://forum.inductiveautomation.com/t/filtering-roster-based-on-user-role/96252 "2024-09-20T19:30:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carson\_Hunter](https://avatars.discourse-cdn.com/v4/letter/c/b9bd4f/32.png) [@Carson\_Hunter](https://forum.inductiveautomation.com/u/Carson_Hunter)\
**Post date:** [September 20, 2024, 7:30pm UTC](https://forum.inductiveautomation.com/t/filtering-roster-based-on-user-role/96252/1 "2024-09-20T19:30:42Z")

</div>

I am working on a project and have come to a crossroads of how to set up user management and On-Call Rosters for the alarm pipeline. There are different zones, Hatchery, Nursery, etc. We have all the tags on different tag providers that are the same as their zone name. The issue is that to setup the alarm pipelines with escalation and zone filtering it seems as if we would need up to 5 different rosters for each zone, which will end up having a large number of rosters. What I am looking to see is if it is possible to filter the users in a roster based on their role. For instance, I would have 5 rosters named Escalation Tier 1-5 and depending on the user role it will be sent to only the users that have the defined roles inside of that roster.

---

<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:** [September 21, 2024, 5:18pm UTC](https://forum.inductiveautomation.com/t/filtering-roster-based-on-user-role/96252/2 "2024-09-21T17:18:08Z")

</div>

Depending on a bunch of things, I might store users in a database table with columns specific to your use case, then pull them in a calculated roster.  
The “bunch of things” includes, but is not limited to:

- who configures those rosters
- can users be in multiple rosters
- how the roles are used in the selection process

---

<div class="post-metadata">

**Author:** ![Carson\_Hunter](https://avatars.discourse-cdn.com/v4/letter/c/b9bd4f/32.png) [@Carson\_Hunter](https://forum.inductiveautomation.com/u/Carson_Hunter)\
**Post date:** [October 3, 2024, 2:06pm UTC](https://forum.inductiveautomation.com/t/filtering-roster-based-on-user-role/96252/3 "2024-10-03T14:06:47Z")

</div>

I worked with Ignition Support to come up with a solution, if anyone else has a use case for this here is what we came up with. Below is the calculated roster that does role and roster filtering inside of a notification block.

```python
	userList = []
	targetRole = 'Enter Role Name'
	rosterName = "Enter Roster Name"
	logger = system.util.getLogger("AlarmPipeline")
	
	try:
	    roster = system.roster.getRoster(rosterName)
	    users = roster.getUsers()
	
	    for user in users:
	        # get user's roles
	        roles = user.getRoles()
	        #logger.info("Roles for user {}: {}".format(user.get(user.Username), roles)) # Log the roles
	
	        # create userInfo object
	        userInfo = {}
	
	        # if user has the targetRole
	        if targetRole in roles:
	            # get the Contact Info of that user 
	            contactInfo = user.getContactInfo()
	            email = []
	            phone = []
	
	            # loop through list of contact info to get email list and phone number list
	            for contactType in contactInfo: 
	                if contactType.getContactType() == 'email':
	                    email.append(contactType.getValue())
	                elif contactType.getContactType() == 'sms':
	                    phone.append(contactType.getValue())
	
	# Log the phone numbers we are collecting
           		#logger.info("Phone numbers for user {}: {}".format(user.get(user.Username), phone))
	
	            # create username and contact info in the userInfo object
	            userInfo['username'] = user.get(user.Username)
	            userInfo['email'] = email
	            userInfo['sms'] = phone
	
	            # append userInfo object to userList
	            userList.append(userInfo)
	
	except Exception as e:
	    logger.error("Error occurred while calculating roster: " + str(e))
	
	return userList

```

I have a main Pipeline that filters the tag based on tag provider and jumps to each individual pipeline that has its own escalation setup based on what zone it comes from and sends it to the correct users.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/3/e3b5dcb3ce11ccd669c713487753699e9ca2df9a.png)

The set property block contains:

```python
split({fullItemPath},'/')[0,0]

```

and the switch simply has the property:

```python
getProperty("tagProvider")

```

It might not exactly be pretty or optimized but it does work correctly.
