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,467,417
Community Members
 
Community Events
177
Community Groups

Scriptrunner Listener send deleted issue custom email "include all fields"

I'm trying to send an email to my admins when issues are deleted for backup. 

Everything seems strait-forward using the Listener creation screen until I get to the part where I need to include all fields into the email. 

I found this helpful post to include all comments: https://community.atlassian.com/t5/Jira-questions/How-to-send-all-Issue-comments-via-custom-Email-using-script/qaq-p/1193521

Any recommendations without listing every single field in the Email Template?

I don't have an issue with listing specific fields, but I'm hoping there is a way to include all system & custom fields without having to list all 700+ custom fields we have in our environment. 

2 answers

1 accepted

0 votes
Answer accepted

I would love to have someone at Adaptavist give me their opinion on how to solve this. 

Hi @Chase Brown

Thank you for opening a support request through Adaptavist support channel. 

Here you can see the Email template that achieved your need. 

Description:
${issue.description}
</p></p>
Custom Field:
<%
com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjects().each { customField ->
    out << "Name: " + customField.getName() + " - Value: " + (customField.getValue(issue) ? customField.getValue(issue) : "No value") + "</p>"
}
%>
</p></p>
Comments:
<%
com.atlassian.jira.component.ComponentAccessor.getCommentManager().getComments(issue).each { comment ->
    out << comment.getBody() + "</p>"
}
%>

Many Thanks and Kind Regards, 

Jose Marques

Adaptavist

0 votes
brbojorque Community Leader Dec 30, 2019

Hi @Chase Brown ,

Here's the code to list all the Custom Fields that are available for the specific Issue, it does not make sense to include those CustomFields that are not available to the issue because it will just be a bunch of NULL values.

import com.atlassian.jira.component.ComponentAccessor

def issueService = ComponentAccessor.getIssueService()
def issue = event.issue

def customFields = ComponentAccessor.getCustomFieldManager().getCustomFieldObjects()

customFields.each{
log.debug("CustomField:" + it.name + "\tValue:" + (it.getValue(issue) ? it.getValue(issue) : '') )
}

Hi @brbojorque, Thank you for your quick response. 

I think we're on track, but as I'm trying to generate an email, I've go to do this using the GStringTemplateEngine. Here's were I'm at so far: 

<%
def issueService = com.atlassian.jira.component.ComponentAccessor.getIssueService()
def customFields = com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjects()
def issue = event.issue

out <<
customFields.each{
log.debug(("CustomField:" + it.name + "\tValue:" + (it.getValue(issue)) ? it.getValue(issue) : 'No Value Provided') )
}
%>

This seems to pull all the custom field names, but not the values. 

I was trying to toy around with including a validation if the field has values, with an if-else, but I haven't made much progress. 

I'd also like to see if I can list them vertically instead horizontally if possible. 

Thanks again for your help! 

Hi @Chase Brown ,

You declared the syntax wrong.

Here's the correct email template, put the out << in the each item in the loop not outside and your ternary operator is not properly enclosed with parenthesis.

<%
def issueService = com.atlassian.jira.component.ComponentAccessor.getIssueService()
def customFields = com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjects()
def issue = event.issue


customFields.each{
out << "CustomField: " + it.name + "\tValue: " + (it.getValue(issue) ? it.getValue(issue) : 'No Value Provided')
out << "<br/>"
}
%>

 

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events