Create multiple issues from a single email
Since JEMH 3.0.0, 2.7.14, 2.6.15
Scenario
With a given email being received, you want to be able to create or comment on multiple issues.
Step-by-step guide
Create a JEMH TestCase, example below, update the 'To' address to match your Profile > Email > Catchemail address. Update the Sender Email to be either valid for your system, or ensure your Profile > User > Default reporter user name is set.
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: <BANLkTinB1mfSh+GwOXGNWoL4SyDvOpdBoQ@mail.gmail.com> Subject: This is a starting email template, update as required From: "Andy Brook" <andy@localhost> To: changeme@thiswontwork.com Content-Type: text/plain; charset=UTF-8 some text
Ensure that Profile > Directives > Directive Processing Behaviour is set to cover the scenario you want (e.g. On Create or Comment)
Ensure that Profile > Field Processors : Script Field Processor is enabled
From the Profile view, edit the Script Field Processor section at the bottom of the screen. On the Edit Script screen, paste the following script, updating values (project, issueType, priority) for your environment:
//create a default issue resultMap.put("labels", "hello-world"); resultMap.put("FORCE_JEMH_SCRIPTFP", true); for (i =0 ; i<3 ; i++) { //print('adding result set #'+i); var newResultSet = jemhUtils.createResultSet(); newResultSet.put("project", "TASK"); newResultSet.put("issueType", "task"); newResultSet.put("priority", "low"); newResultSet.put("reporter", "admin"); newResultSet.put("body", "do this.... \n"+ body); } var newResultSet = jemhUtils.createResultSet(); newResultSet.put("issueKey", "DEF-7"); print('extra result sets'); var extra = jemhUtils.getResultSets().toArray(); for (i =0 ; i<extra.length ; i++) { print('item #'+i+' project='+extra[i].get('project')+',issueType='+extra[i].get('issueType')+',priority='+extra[i].get('priority')); } print('done');
At the bottom of Edit Script screen there is a edit-time Test feature, pick the Test Case you created above and hit Run. You should see something as shown below, indicating multiple ResultSets and their values that will be used to drive issue creation (in this case)
The results only shown in the preview are values extracted from the script field processor. Values generated in the project mappings are not included. If null values are observed then it is possible that these haven’t been set yet and are set in the Project Mappings.
If you now go to the Test Case screen, you can run the Test Case against the profile, the output should be the same
Need the 'user' of the Sender?
See the Script Field Processor context, on the edit screen, scroll down, there is the senderUser if applicable.
Resolving issueKeys from the subject?
In a hypothetical scenario where a subject has several issuekeys, you can just script the extracting with a regular expression, and populate resultsSets starting with the primary '"resultMap", and adding more resultSets as needed.
Example Email with multiple issue keys:
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: <BANLkTinB1mfSh+GwOXGNWoL4SyDvOpdBoQ@mail.gmail.com>
Subject: This is a starting email template, update as required ABC-123 DEF-345 XYZ-678
From: "Andy Brook" <andy@localhost>
To: changeme@thiswontwork.com
Content-Type: text/plain; charset=UTF-8
some text
Example Script:
Results:
Evaluating the above Test Case within the Script Field Processor Test section dynamically shows that the 3 issue keys have been extracted from the subject, and can be set as the "issueKey" to drive commenting behavior, assuming the target issue(s) are in a state that is valid for commenting!
The results only shown in the preview are values extracted from the script field processor. Values generated in the project mappings are not included. In this example the issueType and priority here is null because these values aren’t set in the Script Field Processor and may be set in the Project Mappings configured in the Profile.
Commenting
commenting on issues is just a matter of setting the required "issueKey" attribute of a result map, for example:
Problems with commenting
When commenting, if the Jira user associated with the sender address does not the ability to comment on those issues, the operation will fail.
If the non-Jira user without an account has not previously been involved in those issues, the operation will fail, the auditing result will show the message was filtered:
This can be worked by enabling "Allow Anonymous Commenting" around but this will open your Jira to allow any non-Jira user to comment on ANY issue in ANY project (that the Profile > User : Default Reporter username has access to).
What about custom fields, the description, the summary?
JEMH standard processing will fill in the blanks for issue creation, meaning that the email subject will be used as the summary, the email body will be used as the description (or comment, as applicable), with no further action. Where a given project is resolved (either by referencing the "project" or "issueKey", any Custom Field Default configuration defined will also apply.
The values set within your script are not tied to your Jira Configuration. If you remove an issue type or a project, or change project permission, things will break!