Is it possible to have both "and" and "or" when making conditional routing rules?
Asked by HN:

Working on getting some routing rules setup and running into an issue (more of an annoyance but potential issue based on rules).

Currently I want to create routing rules for the following cases:

Route to team Alpha for:  
- **AND** (Tags contain "A" **OR** -Tag contain "B")  
- **AND** Tag does not contain "X"  
- **AND** Priority \> 3

Route to team Bravo for:  
- **AND** (Tags contain "A" **OR** -Tag contain "B")  
- **AND** Tag does not contain "X"  
- **AND** Priority \> 4  

Is there a way to have the rules contain both AND/OR in the conditions?

As I have multiple teams, tag conditions and priorities to address; it becomes super cumbersome to have a separate rule for each OR condition. I'm not sure if there's a limit to the amount of rules that can be made so it may not be an actual issue but if there's a limit then the split OR conditions essentially doubles the amount of rules I'd need.


Answers:
author: Sean Suwal
body: Hey [@HN,](https://community.atlassian.com/t5/user/viewprofilepage/user-id/5535606)

Thank you for reaching out to Atlassian Community!

Yes, this can be achieved via the use of [Regular expressions for customizing and filtering alerts](https://support.atlassian.com/opsgenie/docs/regular-expressions-for-improved-alert-filtering/)

To use the **OR** condition for an entry you can use the **Matches (Regex)** and then have the values as **.\***(Value1\|Value2\|Value3).\*

Note: The rules are executed in a top-down hierarchy, which means if the first rule matches, it will skip the remaining rules.

Here's an example screenshot of one of the conditions:

![Screenshot 2024-08-16 at 1.08.00?PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/342365i16EB3D80B9527C63/image-size/large?v=v2&px=999 "Screenshot 2024-08-16 at 1.08.00?PM.png")

I hope this helps resolve your query.

Regards,  
Sean

comments: author: HN
body: That's awesome and helps immensely [@Sean Suwal](/t5/user/viewprofilepage/user-id/5078924)!

I don't have permissions to view the screenshot unfortunately.

One more question in addition to the top-down hierarchy. How would you go about having multiple groups getting alerts?

Ideally my situation needs to have cascading alerts, so if Priority is greater than 4, then the rule for greater than 3 would need to be addressed as well as two different teams are on call.

<br />

I've considered having escalation policies for the different teams, having the users for lower priority included in the higher priority escalation but this seemed a bit messy. I'm still learning how to utilize OpsGenie effectively, so I'm eager to know if there's better ways to do things.


author: Sean Suwal
body: Hi [@HN](/t5/user/viewprofilepage/user-id/5535606)

I am glad it was helpful. I have also updated the screenshot, which you should now be able to see.

Based on your requirements, I believe using [**Global alert policies**](https://support.atlassian.com/opsgenie/docs/create-and-manage-global-alert-policies/) would be best suited. With the global policy, you can set your condition which when matched, adds the team(s) you want as responders.

Let us know how you go.

Regards,  
Sean