# Context Resolution Algorithm

### Context Resolution Algorithm <a href="#contexts-contextresolutionalgorithm" id="contexts-contextresolutionalgorithm"></a>

There may be multiple contexts applicable to an issue. The best-matching context is selected for each issue to determine the email template or notification rules that apply to that issue.

Contexts are resolved from the strongest to the weakest match. Here are the steps performed:

1. Find all Contexts that are configured with a project and an issue type, and iterate through each of them in the order of the Order attribute (see above):
   1. if the Context that is being evaluated has a JQL filter, check if the Issue matches it. If so, we stop processing and use the Context.
   2. If the Context that is being evaluated does not have a JQL filter, we stop processing and use the Context.
2. If no Context has been found in the previous step, find all Contexts that are configured with an Issue Type but not with a Project, and iterate through each of them in the order of the Order attribute (see above):
   1. if the Context that is being evaluated has a JQL filter, check if the Issue matches it. If so, we stop processing and use the Context.
   2. If the Context that is being evaluated does not have a JQL filter, we stop processing and use the Context.
3. If no Context has been found in the previous step, find all Contexts that are configured with a Project but not with an Issue Type, and iterate through each of them in the order of the Order attribute (see above):
   1. if the Context that is being evaluated has a JQL filter, check if the Issue matches it. If so, we stop processing and use the Context.
   2. If the Context that is being evaluated does not have a JQL filter, we stop processing and use the Context.
4. If no Context has been found in the previous step, find all Contexts that are not configured with an Issue Type or a Project, and iterate through each of them in the order of the Order attribute (see above):
   1. if the Context that is being evaluated has a JQL filter, check if the Issue matches it. If so, we stop processing and use the Context.
   2. If the Context that is being evaluated does not have a JQL filter, we stop processing and use the Context.
5. If no Context has been found in the previous steps, use an implicit default Context.

### Examples <a href="#contexts-contextexamplesexamples" id="contexts-contextexamplesexamples"></a>

This is how contexts are evaluated based on how well they match an issue:

<table><thead><tr><th width="150"></th><th>Project</th><th>Issue type</th><th>JQL Filter</th></tr></thead><tbody><tr><td>Context 1</td><td>Example Service Management Project</td><td>Bug</td><td>resolution IS EMPTY</td></tr><tr><td>Context 2</td><td>Example Service Management Project</td><td>Bug</td><td>priority = Blocker</td></tr><tr><td>Context 3</td><td>Example Service Management Project</td><td><em>(empty, i.e. applies to all types)</em></td><td>priority = Critical</td></tr><tr><td>Context 4</td><td>Example Service Management Project</td><td><em>(empty, i.e. applies to all types)</em></td><td><em>(empty)</em></td></tr><tr><td>Context 5</td><td><em>(empty, i.e. applies to all projects)</em></td><td>New Feature</td><td><em>(empty)</em></td></tr><tr><td>Context 6</td><td><em>(empty, i.e. applies to all projects)</em></td><td><em>(empty, i.e. applies to all types)</em></td><td>priority = Critical</td></tr><tr><td>Context 7</td><td><em>(empty, i.e. applies to all projects)</em></td><td><em>(empty, i.e. applies to all types)</em></td><td><em>(empty)</em></td></tr></tbody></table>

Some examples of contexts are evaluated for an issue:

| Issue attributes                                                                                                                   | Matching Context | Explanation                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ---------------------------------------------------------------------------------------------------------------------------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <ul><li>Project: Example Service Management Project</li><li>Type: Bug</li><li>Priority: Normal</li><li>Unresolved</li></ul>        | Context 1        | All attributes are directly matching the Context's settings: it's in the right project, has the correct issue type, and the resolution is empty.                                                                                                                                                                                                                                                                                                       |
| <ul><li>Project: Example Service Management Project</li><li>Type: Bug</li><li>Priority: Normal</li><li>Resolution: Fixed</li></ul> | Context 4        | <p>Context 1 does not match the issue as it is resolved (resolution is NOT empty).</p><p>Context 2 does not match the issue as it is of Normal priority (not blocker).</p><p>Context 3 does not match the issue as it is of Normal priority (not critical).</p><p>Context 4 matches the issue, because the issue is in the correct project, the context is applicable to ALL issue types and there is no JQL to put any restrictions on the issue.</p> |
| <ul><li>Project: Internal IT Project</li><li>Type: Bug</li><li>Priority: Critical</li><li>Resolution: Fixed</li></ul>              | Context 6        | <p>Context 1-4 does not match the issue as the issue is in the Internal IT Project not the Example Service Management Project.</p><p>Context 5 does not match the issue as it is a Bug, not a New Feature.</p><p>Context 6 matches the issue as it is of Critical priority and both the project and issue type settings are empty, meaning that they are applicable to all projects and issue types.</p>                                               |
| <ul><li>Project: Internal IT Project</li><li>Type: Task</li><li>Priority: Minor</li><li>Resolution: Fixed</li></ul>                | Context 7        | <p>Context 1-6 does not match the issue as it is not fulfilling the Context attributes (the issue isn't in the Example Service Management Project, it is not a new feature, its priority is not critical).</p><p>Context 7 matches the issue as the Context does not have any restrictions at all.</p>                                                                                                                                                 |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.meta-inf.hu/email-this-issue/email-this-issue-for-jira-server-data-center/documentation/outgoing-emails/contexts/context-resolution-algorithm.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
