Hi,
I would like to know if ScriptRunner has the capability to export the results of a given JQL filter to a CSV and send it as an email to interested parties. I want to create this as a scheduled job that runs automatically.
Thank you!
Why do you need CSV specifically?
You could use the vanilla filter subscription functionality.
Just make sure you create column specifications for your filter then create a group subscription with a recurring schedule.
Jira will send an email to those recipients with a nice table view of all the matching issues.
If you're going to do this as a script will involve a lot of complex scripting tasks.
I don't have a ready function that does all this. And this is a larger effort than I'm prepared to do for free ;)
Hey @Peter-Dave Sheehan , thank you very much for your feedback!
I specifically wanted the CSV because I have a few external users who needs access to our data and they will be uploading it to their systems. Unfortunately, I cannot onboard them to Jira due to licensing limits. So I wanted to automate this task on a weekly basis.
I knew that this CSV generation is a complicated task but anyways I just thought of asking here maybe if someone has any suggestions or ideas for this.
Anyways, It seems like I should export manually and send it to them for now.
Thanks again Pete!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Peter-Dave Sheehan Can we do this?
We could make use of the CSV export link of the search results and download the CSV file onto a path in the server. I have a working code snippet that can fetch the file and send it as an email.
The CSV URL is something like this: hxxps://mycompany.com/sr/jira.issueviews:searchrequest-csv-current-fields/10317/SearchRequest-10317.csv
Maybe if we could develop a code that can access this link and download it onto a desired path, the rest of the task is easy for me.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's a decent idea.
You can look at this other response of mine for how you can access an internal url from groovy.
Here is a snippet for sending emails. You'll have to find out how to attach the file you access from above:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.mail.Email
import com.atlassian.mail.MailException
import com.atlassian.mail.MailFactory
import com.atlassian.mail.queue.SingleMailQueueItem
import com.atlassian.mail.server.MailServerManager
import com.atlassian.mail.server.SMTPMailServer
MailServerManager mailServerManager = ComponentAccessor.mailServerManager
SMTPMailServer mailServer = mailServerManager.defaultSMTPMailServer
if (!mailServer || MailFactory.settings.sendingDisabled) {
log.warn "Unable to send. No server found or sending is disabled"
return 'Disabled'
}
Email email = new Email('to1@example.com to2@example.com')
email.from = mailServer.defaultFrom
email.subject = "your subject"
email.body = "your body"
try {
SingleMailQueueItem item = new SingleMailQueueItem(email)
ComponentAccessor.mailQueue.addItem(item)
return "Success"
} catch (MailException e) {
return "Failed"
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I did it @Peter-Dave Sheehan ! YaY
Here is my entire code.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Nice!
If you feel I've earned it, please remember to flag this thread as "accepted"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Shamanth ! can you please tell how to find directory where the csv is saved? (def file1 = new File('var/lib/jira/scripts/export1.csv' in your case)
is export1.csv file name standard, or it can be different?
Thanks beforehand!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Akbar Gulaliyev ,
The response from the filter output is written to a file by these lines:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello again @Peter-Dave Sheehan !
Do you have any suggestions or codes with you that can do this job for me on ScriptRunner?
Thanks in advance :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You would need to code that job to do the jql search, construct your .csv out of it, and then add it as an attachment to an email to send to the recipients.
At the same time though, this is possible to do without any plugins, all you'd need to do is do the .csv export and capture the HTTP request (which will be in a static format that can be reused). This gives you the file source. How to send that email is the remaining part, but a cron job might do it as well provided you can create a new mail with it and pass it to the mail server.
As far as I know ScriptRunner doesn't have any such automated .csv export without coding it yourself. If you don't specifically need .csv you can always set up the out of box filter subscription, which will send a csv-formatted html mail with the search result. Not specifically a .csv file though.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.