...
Code Block |
---|
var newResultMap = jemhUtils.createResultSet(); newResultMap.put("issueKey", "COREONE-29"); |
...
Create Issues for each Catch Email address
Status | ||||
---|---|---|---|---|
|
Scenario
You may want to create multiple issues from a single email based on the email recipients. For example, a customer might CC another email address within your organisation specific to a different Jira Project. In this case, one email should create two issues, one for each recipient.
Implementation
...
...
The jemhUtils
class can be used to create a list of Result Maps for each Catch Email address match in the email. This is specific to the Profile the script is used in. Please see the following example:
...
Code Block |
---|
var additionalResultMaps = jemhUtils.createResultSetForEachMailboxAddresscreateResultSetForAdditionalMailboxAddresses(); print(additionalResultMaps); |
...
Code Block |
---|
var resultSetList = jemhUtils.createResultSetForEachMailboxAddresscreateResultSetForAdditionalMailboxAddresses(); jemhMapperUtils.findProjectForResultMapsfindProjectKeyForResultMaps(resultSetList); print(resultSetList); |
...
As previously mentioned Project Mappings are only applied to the initial ‘Result Map’. In order to apply values from the Project Mapping to newly created Additional Result Maps, another method of the jemhMapperUtils can be used, 'applyProjectMappingDomainRules
applyProjectMappingDomainRulesToResultMaps
'.
Example
Using a pre-defined Domain Rules as an example:
...
Code Block |
---|
var resultSetList = jemhUtils.createResultSetForEachMailboxAddresscreateResultSetForAdditionalMailboxAddresses(); jemhMapperUtils.findProjectForResultMapsfindProjectKeyForResultMaps(resultSetList); print(resultSetList); jemhMapperUtils.applyProjectMappingDomainRulesapplyProjectMappingDomainRulesToResultMaps(resultSetList); |
Using the Testcase from the previous example will result in the following outcome:
...
To then associate issues via Script the Script can make use of the 'resolveAssociatedIssuesViaMessageId
resolveFilteredIssueAssociationByMessageIdForAdditionalResultMaps
' of the 'jemhThreadUtils
' class.
The 'resolveAssociatedIssuesViaMessageId
resolveFilteredIssueAssociationByMessageIdForAdditionalResultMaps
' method requires the following parameters in order to associate issues:
mapList: A list of all Result Maps that should have issue association resolved based on the Message ID.
user: The user used to associate issues. The user must have access to the issue in order to associate the email to the issue. Typically, an Administrator user would be used, however the email sender could be used to limit access
customField: The onIssueIDField: The ID of the custom field the Message ID of the email will be stored in on the issue
applyFiltering: A boolean value which dictates if issue association conditions derived from the JEMH Profile configuration are applied. True: Do apply filtering, False: Do not apply filtering
Script
The following script makes use of both the 'resolveAssociatedIssuesViaMessageId
' method to resolve issue association for a list of Result Maps and 'resolveAssociatedIssueViaMessageId
' which resolves issue association for a single Result Map
...
.
Script
Code Block | ||
---|---|---|
| ||
// For a more detailed description of this method and its implementation please see the following Documentation Page: https://thepluginpeople.atlassian.net/l/cp/w09QeNY4
if(jemhUtils.getCatchEmailAddress())
{
// Gets the first Catch Email Address for the email
var caughtRecipient = jemhUtils.getCatchEmailAddress().getAddress();
// Sets the Result Map's '_jemh_recipient' to the actual caught Email address
resultMap.put("_jemh_recipient", caughtRecipient);
// Creates a list of Result maps from the email addressees that are Catch Email Address matches with the '_jemh_recipient' key containing the Catch Email Address.
var resultSetList = jemhUtils.createResultSetForAdditionalMailboxAddresses();
// Adds the resultMap to the List of additional resultMaps. This is done to make iterating through each resultMap for issue association easier
resultSetList.add(resultMap);
// Finds the Project key associated (based on addressee Domain Rules only) with each resultMap based on the '_jemh_recipient' key. If no project is found, the Project Key of the Default Project Mapping will be used
// Establishes only the Project Key for the Result Map
jemhMapperUtils.findProjectKeyForResultMaps(resultSetList);
// The Issue keys for each resultMap are resolved based on the Message ID. To summarize the method, a hash of the Message ID (we have to hash to ensure the value can be queried with JQL) of the email is used to establish if any other issues
// in the project have the same hash in the custom field specified by the the 'externalIdField'. Any Issues found via a bounded JQL query (max 10) are sorted by creation date (Ascending). As this is a 'Filtered' method variant, any
// thread match conditions defined in the profile are run against the viable issues. removing any issues that do not meet this criteria. Finally a single (created first and valid) issue is selected, and the issueKey is added to
// the Result Map. If no match is found, the hashed Message ID is added to the specified Custom field (e.g. "customfield_10122") for future association
// TLDR: Issues are resolved for each of the provided Result Maps based on a hashed Message ID stored on the Custom field e.g. "customfield_10122"
// Adds pre-existing Issue Keys for previously established Projects in the Result Map
jemhThreadUtils.resolveFilteredIssueAssociationByMessageIdForAdditionalResultMaps(resultSetList, "customfield_10122");
// Based on the defined project in the result map, and the '_jemh_recipient', any valid Domain Rule configurations and project mapping values are applied to the result set, as if the email had been mapped to a specific project.
// Add in all appropriate Field values from the Domain Rule and its parent Project Mapping i.e. Issue Type Priority, etc.
jemhMapperUtils.applyProjectMappingDomainRulesToResultMaps(resultSetList);
}
else
{
print("No Catch Email Address found between Email Recipients and Profile > Email > Catch Email Address");
} |
Example Emails
The following example emails can be used to validate issue association via Script.
...
Code Block |
---|
MIME-Version: 1.0 Received: by 10.223.112.12 with HTTP; Sat, 18 Jun 2011 22:42:26 -0700 (PDT) Date: Sun, 19 Jun 2011 17:42:26 +1200 Message-ID: <ISSUE-COMMENT-TESTCASE-TEST@mail.gmail.com> In-Reply-To: <ISSUE-CREATION-TESTCASE-TEST@mail.gmail.com> Subject: This is a starting email template, update as required From: "Andy Brook" <user1@test.com> To: test@test.com, blue@test.com Cc: green@test.com Content-Type: text/plain; charset=UTF-8 some text |
Outcome
...
Associate with External ID via Script
The jemhThreadUtils
class also allows for issues to be associated via an external ID. This allows values other than the Message ID to be used. As an example, a value from the Subject. Typically this requires some additional configuration as the external ID must be identified in the email manually. For a detailed walk through of this scenario please see: