$customHeader
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 Current »

This script is to be used in the Script Field Processor (Use Script Field Processor ) and requires emails to have an issue key in the subject in order to identify the issue that is to be commented on.

Overview

Summary: Add Jira user senders to a multi user picker Custom Field on an issue if they are not already present, when commenting on an issue.

Here is a quick rundown of what this script does:

  • Check if the email sender is a Jira user

  • If they are a Jira user, check the subject for an issue key (this shows the email is commenting on an existing issue)

  • If an issue key is found, locate the issue to be commented on using this key

  • Extract the current values of the Custom Field

  • Check if the sender is already in this field

  • If they are not, then they will be added

Example Script

var from = fromAddress.getAddress();
var jiraUser = jemhUtils.getUserByEmail(from);
if(jiraUser == null)
    {
        print("Sender was not a Jira User");
    }
    else
    {
      var pattern = Java.type("java.util.regex.Pattern").compile"([A-Z]+-[0-9]+)");
      var matcher = pattern.matcher(subject);
      if(matcher.find()){
          var group = matcher.group(1);
          var issue = issueManager.getIssueObject(group);
          var jiraUserField = customFieldManager.getCustomFieldObjectByName("Jira Users Field");
          var jiraUsers = issue.getCustomFieldValue(jiraUserField);
          if(!jiraUsers.contains(jiraUser)){
              jiraUsers.add(jiraUser);
              print(jiraUsers);
              resultMap.put("Jira Users Field", jiraUsers);
          }
    }
}

On line 14 and line 19, change 'Jira Users Field' to the name of your user picker Custom Field.

Please Note: This script only works for comments that are added to existing issues. If you want to add a Jira User sender to a Custom Field on CREATE, this can be done in Email → Sender Processing in your profile.

  • No labels