Associate issue creation and other events with initial email Thread

By default configurations in JEMH when the email has been sent and the issue is created in Jira, the notification received of the issue creation will create a new email thread and all further communication will be associated with this newly created email Thread. In order to associate the issue creation notification and all other event notifications with the initial email sent requires to apply additional configurations. The following example is based on using a Gmail email client.

Gmail requirements to satisfy the email threading

In order for email to be threaded in Gmail conversation view, the following must present in the notifications:

  • Have the same subject

  • Have reference headers that reference IDs seen earlier in the thread, or have references headers that consistently refer to the same message ID

Step-by-step guide

1. Add Issue Entity Properties

Navigate to JEMH > Profile > Issue and enable Add Issue Entity Properties functionality. This is required to enable JEMH to store the incoming message Message-ID, References and In-Reply-To headers during issue creation. Entity Properties can only be set after the issue is created, so the CustomOnCreate event is needed for create notifications to be tagged. Subsequent (comment/update) notifications will be threaded with the standard Jira thread ID, but also with the References header containing the set of IDs stored against the issue.

NOTE: Setting Entity Properties is considered by Jira to require EDIT_ISSUE permission, so is not enabled by default.

2. Create a Jira Custom Event and Associate with Notification Scheme

  • You will need to create a custom Issue Create Event. Please see the following documentation on how to add/create a custom event: Adding a custom event

Under Jira > System > Advanced > Events add new event

Once added the new Event it will appear under existing ones

  • After created, edit the Default Notification Scheme to include the usual Reporter/Assignee/All Watchers combo (or whatever you need). Therefore, navigate to Jira > Project Settings > Notifications you will see your newly created event which is empty.

To add recipients to the event, you can do it on the same page under Actions > Edit notifications

 

Then scroll down to your custom event and click on Add. In this example, the following recipients have been added

Once you have added all desired recipients, make sure that Project Notification Scheme has been disabled. JEMH requires that the projects for which JEMH should handle notifications have no notification scheme selected, as leaving it enabled will generate JIRA standard notifications as well as JEMH notifications.  This can be done through JIRA > Project Administration > Notifications > Actions > Use a different scheme > Select Scheme (none):

Make a note of what the notification scheme is called, you need it later!

3. Selection of newly created custom Issue Create Event

Pick the custom event in the Profile, note this means JEMH will fire first ISSUE_CREATED and then the CUSTOM_EVENT. Navigate to JEMH > Profile > Notifications and select your custom issue create event in the On Create Custom Event field

In the next step we set ‘something’ on the issue to indicate that JEMH created the issue, then during notification we can ‘ignore’ the JEMH ISSUE_CREATED notifications as we also expect the custom event.

4. Creating a custom field

After enabling a custom event and enabling JEMH notifications, JEMH will actually sent two notifications. The first in response to Issue Created, and  the second due to Custom Event. You would normally want to inhibit the notification when it was driven by JEMH, rather than an interactive user. The suggested approach is to set a Custom Field default value on Create to identify the source as JEMH, this Custom Field value can then be detected int the JEMH notification section and used to filer/stop the Issue Created notification.

Create a single line text Custom field called CreatedByEmail for the purpose of flagging issues create by JEMH. How to create a custom field see the following Create a custom field.

Once the custom field has been created set a Default Project Mapping Custom field Default for that field under JEMH > Profile > Project Mappings > Custom Field Defaults, it will be inherited by all Rule-mapped Project Mappings.

When selecting the field, make a note of the customfield_xxxxxx value shown, you’ll need it in the following step.

5. Creation of the custom template

In order to retain the same email subject as the initial email, you will need to create custom templates for each issue event you will need to send notifications and remove the IssueKey from the subject.

This can be done under JEMH > Template Sets

By default the Subject contains IssueKey

IssueKey needs to be removed in order to retain the same email subject as the initial one

6. Setup Outbound Notifications

Navigate to JEMH > Notifications > Jira Notifications > Edit. Here we will apply the Event Selector and Filter script and enable a few other functionalities to prevent duplicate Issue Creation notifications and retain the same email subject as the initial email.

  • Exclude Subject Prefix

  • Event Selector and Filter script

    #set($cf = $customFieldManager.getCustomFieldObject("customfield_10122")) #set ($cfValue = $issue.getCustomFieldValue($cf)) #if ($issueEvent.getEventTypeId() == "1" && $cfValue == "Email") $result.setIgnoreEvent(true) $result.setReason("Stop duplicate") #else Its normal, leave alone #end
  • Event Template Selection
    Select all your custom templates for the corresponding events to be fired

Result

  • The initial email has been sent to create an issue in the Jira

  • The issue has been created and the custom field has been populated with the Email value

  • Issue creation notification has been added to the initial email thread