The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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
To get custom field value you must
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The 2020 acquisition of Mindville added powerful asset and configuration management capabilities to Jira Service Management in the form of Insight. Following the completion of that integration, custo...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.