...
This script will find and gather a Custom Field value from the related issue and will then add the value from the Custom Field to the new issue that is being created.
Info |
---|
Note: The method ' |
Code Block |
---|
if (relatedIssue === null) //Checks if the email is commenting on a issue. { var allReferences = jemhUtils.getReferencedMessageIds().toString(); //Gathers all of the References from the email to check if a Issue Message-Id is found if(allReferences !== null && !allReferences.isEmpty()){ //Checks if the returned reference headers are null or empty var referencesString = allReferences.toString(); //Converts all reference Headers to a single string var pattern = Java.type("java.util.regex.Pattern").compile("JIRA\.([0-9]+)\."); //RegexCompiles a Regexp Pattern to extract only the IssueId from the MessageReference-Id var matcher = pattern.matcher(allReferencesreferencesString); if(matcher.find()){ //Runs if a match is found { var group = matcher.group(1); //Gathers the first group RegexRegexp match. In this case the Issue ID var matchedIssueidAsLong = issueManagertextUtils.getAllIssueKeysparseLong(group).toString().replace("[", "").replace("]", ""; //Converts the Issue ID String into a number of type 'Long' if(issueManager.getIssue(idAsLong) !== null){ //Checks if an issue with the ID present in the reference header is valid var matchedIssue = issueManager.getIssueObject(idAsLong); //Searchs forRetrieves the issue withusing the id Issue ID var fieldObject = customFieldManager.getCustomFieldObjectByName("exampleSource"); //CreatesGets athe Custom Field Object for the relevant Custom Field, "example" needs to be changed if(fieldObject !== null){ //Checks if the Custom Field is valid var fieldValue = issueManager.getIssueObject(matchedIssue).getCustomFieldValue(fieldObject); //ChecksRetrieves for athe value withinof the issueCustom Field thatpresent matchedon the Id Matched Issue if (fieldValue !== null){ // Checks if there is a value set, If there is then add this value to new issue { print("value was found on the related issue: "+ matchedIssue); resultMap.put("example", fieldValue); //Sets value on the new issue, "example" needs to be changed to the field name } } } } } } |