Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Scenario

You have Threat Match Condition set to Open Issue Only and this is resulting in JEMH creating a new issue instead of commenting on the related Issue but you would like to extract a field from the related issue to then be added to the new issue.

Implementation

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.

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
    
    var pattern = Java.type("java.util.regex.Pattern").compile("JIRA\.([0-9]+)\."); //Regex to extract only the IssueId from the Message-Id
    var matcher = pattern.matcher(allReferences);
        if(matcher.find()) //Runs if a match is found
        {
            var group = matcher.group(1); //Gathers the first Regex match
            var matchedIssue = issueManager.getAllIssueKeys(group).toString().replace("[", "").replace("]", ""); //Searchs for the issue with the id
            var fieldObject = customFieldManager.getCustomFieldObjectByName("example"); //Creates a Custom Field Object for the relevant Custom Field, "example" needs to be changed
            var fieldValue = issueManager.getIssueObject(matchedIssue).getCustomFieldValue(fieldObject); //Checks for a value within the issue that matched the Id
            
            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
            }
        }
        
}

  • No labels