Versions Compared

Key

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

...

Code Block
// For more detail and background information regarding this Script please see the following Documentation: https://thepluginpeople.atlassian.net/l/cp/CZKAm2Vw
// Create Regexp pattern to extract external id
var pattern = Java.type("java.util.regex.Pattern").compile("Case\\s#:\\s([0-9]+)");
var matcher = pattern.matcher(body);
var foundExternalId = "";

// Set the value of the Custom Field which will hold the External ID value on the Issue
var externalIDField = "customfield_10122";
 
// If able to extract issue key, set variable
if (matcher.find()) {
    var group = matcher.group(1);
    if (group) {
        foundExternalId = group;
    }
}
 
var issueWithExternalId = "";
if (foundExternalId) {
    print("external ID extracted: "+foundExternalId);
    
    // Use Thread Utils to find a list of Issues which hold the 'foundExternalId' in the 'externalIDField'. This method will 
    // apply Thread Match conditions defined in the Profile (only match open issues, matches JQL, etc.). 
    // Additionally, the returned list will be ordered by Creation Date (Ascending) therforetherefore the Issue at index 0 would be the oldest valid Issue
    var results = jemhThreadUtils.getFilteredAssociatedIssuesFromExternalId(externalIDField, foundExternalId);
      
    // Get first issue if exists and add via issueKey directive (Could be empty)
    if (results.size()>0) {
        var issue = results[0];
        issueWithExternalId = issue.getKey();
        print("Found issue using External ID match:"+issueWithExternalId);
    } else {
        print("No issues match found using External ID match");
    }
}
 
if (!issueWithExternalId.isEmpty()) {
        resultMap.put("issueKey",issueWithExternalId)
} else if (!foundExternalId.isEmpty()) {
        resultMap.put(externalIDField, foundExternalId);
}

...