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

Chase Brown December 30, 2019

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
Chase Brown January 10, 2020

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

jmarquesadaptavist January 16, 2020

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 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) : '') )
}
Chase Brown December 31, 2019

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! 

brbojorque
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 10, 2020

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
AUG Leaders

Atlassian Community Events