Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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
Community showcase
Published in Jira Service Management

JSM June Challenge #2: Share how your business teams became ITSM rockstars

For JSM June Challenge #2, share how your non-technical teams like HR, legal, marketing, finance, and beyond started using Jira Service Management! Tell us: Did they ask to start using it or...

194 views 6 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you