...
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 (Manual)
Implementation (Automatic)
Status | ||||
---|---|---|---|---|
|
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 issueapplyFiltering: 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
...
Code Block |
---|
//Creates a list of Result maps which use the '_jemh_recipient' key to specify the recipient used to generate the ResultMap var resultSetList = jemhUtils.createResultSetForEachMailboxAddresscreateResultSetForAdditionalMailboxAddresses(); jemhMapperUtils.findProjectForResultMaps(resultSetList); var user = userManager.getUserByName("admin"); var customFieldId = "customfield_10122"; var customField = customFieldManager.getCustomFieldObject(customFieldId); jemhThreadUtils.resolveAssociatedIssuesViaMessageId(resultSetList, user, customField, false); jemhThreadUtils.resolveAssociatedIssueViaMessageId(resultMap, user, customField, false); jemhMapperUtils.applyProjectMappingDomainRules //Gets the 'initial' catch email address, which initially matched to create the 'original' ResultMap var caughtRecipient = jemhUtils.getCatchEmailAddress().getAddress(); //Sets the Result Map's '_jemh_recipient' to the actual caught Email address resultMap.put("_jemh_recipient", caughtRecipient); //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 to each resultMap based on the '_jemh_recipient' key. If No project is found, the ProjectMapping default will be used jemhMapperUtils.findProjectKeyForResultMaps(resultSetList); //Sets the customField Id used for Issue Association. The Issue keys for each resultMap are resolved based on the Message ID. To summarize the method, a hash of the Message ID 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 which do not meet this criteria. Finally a single (created first and valid) issue is selected, and the issueKey is added to // the Result Map. var externalIdField = "customfield_10122"; jemhThreadUtils.resolveFilteredIssueAssociationByMessageIdForAdditionalResultMaps(resultSetList, externalIdField); //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. jemhMapperUtils.applyProjectMappingDomainRulesToResultMaps(resultSetList); |
Example Emails
...