I have a Project where I would like to have an automated daily report at midnight.
It should create an excel file or csv file with the subject and the custom field 'auftrag'.
See attached screenshot.
How can I do this?
you could create an issue search and use the subscription to send it daily
but this will be a mail with the jira format, no excel, but you can copy it into excel
Hi Thomas,
You can do this with apps like JMWE or Scriptrunner. Here's the example how to create a CSV file and send it via email:
import com.atlassian.jira.component.ComponentAccessor
import java.io.File
import com.atlassian.mail.Email
import com.atlassian.mail.server.MailServerManager
import javax.mail.internet.MimeBodyPart
import javax.mail.internet.MimeMultipart
import javax.activation.FileDataSource
import javax.activation.DataHandler
//Define mail settings
def mailServerManager = ComponentAccessor.getComponent(MailServerManager)
def recipient = "example@example.com"
def subject = "Email Subject"
def body = "This is the example email."
//Define where the file will be located
def file = new File('/home/jira/jira-data/export/report.csv')
def fileSource = new FileDataSource(new File('/home/jira/jira-data/export/report.csv'))
//Define JQL
//def issues = jqlSearch("jql", MAX_RESULTS)
def issues = jqlSearch("project = 'Production Findings' AND Auftrag is not EMPTY", 1000)
//Define CSV header
file.write("Issue Key,Summary,Auftrag")
file.append("\n")
for (issue in issues) {
def key = issue.get('issuekey')
def summary = issue.get('summary')
def auftrag = issue.get('Auftrag')
file.append("$key,$summary,$auftrag")
file.append("\n")
}
if (fileSource) {
def multipart = new MimeMultipart()
def textPart = new MimeBodyPart()
textPart.setText(body)
multipart.addBodyPart(textPart)
def attachmentPart = new MimeBodyPart()
attachmentPart.setDataHandler(new DataHandler(fileSource))
attachmentPart.setFileName(fileSource.getName())
multipart.addBodyPart(attachmentPart)
def email = new Email(recipient)
def mailServer = mailServerManager.defaultSMTPMailServer
email.setSubject(subject)
email.setMultipart(multipart)
def threadClassLoader = Thread.currentThread().contextClassLoader
Thread.currentThread().contextClassLoader = mailServer.class.classLoader
mailServer.send(email)
Thread.currentThread().contextClassLoader = threadClassLoader
}
else {
log.error("The file is not found.")
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Show up and give back by attending an Atlassian Community Event: we’ll donate $10 for every event attendee in March!
Join an Atlassian Community Event!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.