Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

I am looking for scriptrunner code to add the multi select fields value in a custom email


I have created a custom email post function to send an email to approvers for approving an access. This access field is a multiselect field in JIRA.

How to add the script to display multi-select field value on  email. 

Here is my email code that works fine

import com.atlassian.jira.mail.Email
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager

def groupManager = ComponentAccessor.getComponent(GroupManager.class)
def groupUsers = groupManager.getUsersInGroup("NPPMO-PRV-APPROVAL-GROUP")
def baseurl = ComponentAccessor.getApplicationProperties().getString("jira.baseurl")
//Email body template
def body=" Hello, <br> <br> Privilege Access Approvers, <br> <br> Please note that a new member account request has been created and Privielege Access is requested. Please log in to JIRA to review the details and click on Approve or Reject transition accordingly"
body+="<br><br>The link for Ticket details in Jira is provided below. <br> <br> Thanks. <br><br><br><br>"
body+="<br>Summary: ${issue.summary}"
body+="<br>Issue Key: <a href=$baseurl/browse/$issue.key> ${issue.key}</a>"
body+="<br>URL: ${baseurl}/browse/$issue.key"
body+="<br>Issue Type: $"
body+="<br>Reporter: $issue.reporter.displayName"
body+="<br>Assignee: $issue.assignee.displayName"
//body+="<br>PrivilegeAccess: $issue.privilegeaccess.displayName"

//Email subject
def subject="($issue.key) ${issue.summary} | Your Approval Required for Privilege Access"

//def thetext = ""
groupUsers.each() {
// thetext += it.getDisplayName() + it.getEmailAddress()+ "(" + it.getName() + ")<br>"
sendEmail(it.getEmailAddress(), subject, body)

// send email
def sendEmail(String emailAddr, String subject, String body) {
def mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer()
if (mailServer) {
Email email = new Email("")
// email.setFrom("")

//log.error "Email address:" + emailAddr
//log.error "Subject: " + subject
//log.error "Body: " + body
//log.error("Mail sent")

} else {
log.error("Please make sure that a valid mailServer is configured")
//return thetext


Just want to display the multiselect field value to show the tool list that needs access approval




1 answer

1 accepted

0 votes
Answer accepted

To get custom field value you must

  1. first, get a custom field object
  2. then get the value from the issue (array of "options)
  3. then collect the value from those options
  4. and finally, join the elements in the array for the email body 
def customFieldManager = ComponentAccessor.customFieldManager
def multiSelectField = customFieldManager.getCustomFieldObjectByName("name of your multi select")
//def multiSelectField = customFieldManager.getCustomfFieldObject(123456) //id of the custom field

customFieldValues = issue.getCustomFieldValue(multiSelectField).collect{it.value}.join("<br>"

Also, did you know that you can do this in groovy? Makes the code/email body much easier to read and visualize the final format.

def body="""
   Privilege Access Approvers,
   Please note that a new member account request has been created and Privielege Access is requested. Please log in to JIRA to review the details and click on Approve or Reject transition   accordingly
   The link for Ticket details in Jira is provided below.


   Summary: ${issue.summary}
   Issue Key: <a href=$baseurl/browse/$issue.key> ${issue.key}</a>
   URL: ${baseurl}/browse/$issue.key
   Issue Type: $
   Reporter: $issue.reporter.displayName
   Assignee: $issue.assignee.displayName


thanks a lot. looks so clean.

I will follow the steps above and try to add in email body. thankyou

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events