Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
if (relatedIssue === null) //Checks if the email is commenting on a issue.
{
    var allReferences = jemhUtils.getReferencedMessageIds(); //Gathers all of the References from the email
    
    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]+)\."); //Compiles a Regexp Pattern to extract only the IssueId from the Reference-Id
        var matcher = pattern.matcher(referencesString);
        
        if(matcher.find()){ //Runs if a match is found
            var group = matcher.group(1); //Gathers the first group Regexp match.  In this case the Issue ID 
            var idAsLong = textUtils.parseLong(group); //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); //Retrieves the issue using the Issue ID
                var fieldObject = customFieldManager.getCustomFieldObjectByName("Sourceexample"); //Gets the 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 = matchedIssue.getCustomFieldValue(fieldObject); //Retrieves the value of the Custom Field present on the 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
                    }
                }
            }
        }
    }
}

...