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

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

Avatar

1 badge earned

Collect

Participate in fun challenges

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

Challenges
Coins

Gift kudos to your peers

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

Recognition
Ribbon

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!

Leaderboard

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
4,461,677
Community Members
 
Community Events
176
Community Groups

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

Edited

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.security.groups.GroupManager
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>"
body+="<br>$issue.key<br>"
body+="--------------------------------------------------------<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>Project:$issue.project.name"
body+="<br>Issue Type: $issue.issueType.name"
body+="<br>Reporter: $issue.reporter.displayName"
body+="<br>Assignee: $issue.assignee.displayName"
//body+="<br>PrivilegeAccess: $issue.privilegeaccess.displayName"

body+="<br>--------------------------------------------------------<br>"
//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("temporary@example.com")
email.setTo(emailAddr)
//email.setReplyTo("dojosupport@publicis.sapient.com")
// email.setFrom("dojosupport@publicis.sapient.com")

//log.error "Email address:" + emailAddr
email.setSubject(subject)
//log.error "Subject: " + subject
email.setBody(body)
//log.error "Body: " + body
email.setMimeType("text/html")
mailServer.send(email)
//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="""
   Hello,
   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.

   Thanks.

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

   --------------------------------------------------------
""".stripIndent().replaceAll("\n","<br>")

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
TAGS

Atlassian Community Events