Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to send a list of emails in an HTML formatted string with script runner

Nikhil Guntupalli May 3, 2020

Automatic e-mail to a specific group or to many users of a report/filter query that shows all the changes needing to be implemented in a specific date for the infrastructure services platform changes.   I believe having talked to Prashant, there is a plug-in add that needs to be installed to enable this capability (as an add-on it is free of charge). This will enable the team to plan and schedule each day based on implementation priorities - rather than being reactive to continual questions relating to whether changes have been implemented or not.

1 answer

1 accepted

0 votes
Answer accepted
Matthew Clark
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 5, 2020

Hi Nikhil

I assume based on the support ticket I spoke to you on that you mean "How to send a list of Issues in an HTML formatted table via an email"

I wrote a script that can do this and I am in the process of adding to our Adaptavist script library

For now, you can view the script here.

You can use the script to work out how you can:

  1. Get a list of issues with a JQL search
  2. Format the list of issues into an HTML table
  3. Send an email with the HTML table containing your issues.

<This is the Jira 7 version only.>

Please try it on a test server to see how it works first

 

Regards

Matthew

Nikhil Guntupalli May 19, 2020

Hi @Matthew Clark 

I am facing an issue after adding custom field as below.

Script:

static String buildHTMLTableOfIssues(List<Issue> inputIssues, Boolean debug = false) {

def log = Logger.getLogger(getClass())
log.setLevel(Level.INFO)
if (debug) {
log.setLevel(Level.DEBUG)
}

// def ChangeStart = getFieldByName("Change Start Date / Time").getValue()
// def ChangeEnd = getFieldByName("Change End Date / Time").getValue()
// log.warn("No issues found with ${ChangeEnd} ${ChangeStart}")
def baseUrl = ComponentAccessor.getApplicationProperties().getString("jira.baseurl")
def writer = new StringWriter()
def html = new MarkupBuilder(writer)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def ChangeStart = customFieldManager.getCustomFieldObjects().findByName("Change Start Date / Time")
def ChangeEnd = customFieldManager.getCustomFieldObjects().findByName("Change End Date / Time")


html.html {
head {
style(type: "text/css",
'''
#myTable, th, td{
border: 1px solid black;
padding: 8px;
text-align: left;
}

#myTable {
border-collapse: collapse;
}

''')
}

body(id: 'mainBody') {

table(id: "myTable") {
tr {
th("Key")
th("Summary")
th("Status")
th("Change Start Date")
th("Change End Date")
}
inputIssues.each { issueObj ->
tr {
td {
a(href: "$baseUrl/browse/$issueObj", "${issueObj.key}")
}
td(issueObj.summary.toString())
td(issueObj.status.getName().toString())
td(issueObj..getName().toString())
td(ChangeStart ? (issueObj.getCustomFieldValue(ChangeStart).toString()) : "Invalid field1")
td(ChangeEnd ? (issueObj.getCustomFieldValue(ChangeEnd).toString()) : "Invalid field2")
}
}
}
}
}


String finalHTML = writer.toString()
log.debug("Resulting HTML=")
log.warn(finalHTML)

return finalHTML
}

 

 

Error Log:

2020-05-19 14:25:25,253 ERROR [common.UserScriptEndpoint]: ************************************************************************************* 2020-05-19 14:25:25,253 ERROR [common.UserScriptEndpoint]: Script console script failed: java.lang.ClassCastException: com.atlassian.jira.issue.IssueImpl cannot be cast to java.lang.Comparable at Script185$_buildHTMLTableOfIssues_closure2$_closure4$_closure5$_closure7$_closure8.doCall(Script185.groovy:110) at Script185$_buildHTMLTableOfIssues_closure2$_closure4$_closure5$_closure7$_closure8.doCall(Script185.groovy) at Script185$_buildHTMLTableOfIssues_closure2$_closure4$_closure5$_closure7.doCall(Script185.groovy:104) at Script185$_buildHTMLTableOfIssues_closure2$_closure4$_closure5.doCall(Script185.groovy:103) at Script185$_buildHTMLTableOfIssues_closure2$_closure4$_closure5.doCall(Script185.groovy) at Script185$_buildHTMLTableOfIssues_closure2$_closure4.doCall(Script185.groovy:95) at Script185$_buildHTMLTableOfIssues_closure2$_closure4.doCall(Script185.groovy) at Script185$_buildHTMLTableOfIssues_closure2.doCall(Script185.groovy:93) at Script185$_buildHTMLTableOfIssues_closure2.doCall(Script185.groovy) at Script185.buildHTMLTableOfIssues(Script185.groovy:76) at Script185$buildHTMLTableOfIssues.callStatic(Unknown Source) at Script185.run(Script185.groovy:48)

 

 

Can you please help me out?

Matthew Clark
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 19, 2020

Hi Nikhil

You have too many . characters here:

td(issueObj..getName().toString())

change it to

td(issueObj.getName().toString())

 

Regards

Matthew

Nikhil Guntupalli May 19, 2020

Thanks for the help @Matthew Clark 

Suggest an answer

Log in or Sign up to answer