Hi all! Please, I really need your help in scriptrunner.
I'm trying to make a report on the average task completion time for certain employees.
Target : The report should be parsed with jql and send the result to the mail.
My report in scriptrunner does not work. (Unfortunately, I don’t have the opportunity to buy plugins, but thanks for having them at all)
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.bc.issue.search.SearchService;
import com.atlassian.jira.web.bean.PagerFilter;
import com.atlassian.mail.Email;
issueManager = ComponentAccessor.getIssueManager();
customFieldManager = ComponentAccessor.getCustomFieldManager();
regprov_sla = customFieldManager.getCustomFieldObjectByName("SLA_US_Reaction");
// Body
results = '<html><body><h3>Report</h3><br>'
results += '<b> Report project : REGPROV</b>.<br />'
results += '<table><tr><th>Assignee</th><th>Average task completion time</th><th>Amount ticket</th></tr>'
jql = 'project = REGPROV AND status = Closed AND resolved >= startOfWeek() AND assignee in (a.emelyanenko, g.voytovich, e.povaga, a.avramenko)'
issues = getIssues(jql)
assignee = getAssignee(issues)
results += '<tr><td>'+t+'</td><td>'+(avh/count).toInteger().toString()+'</td><td>'+count.toString()+'</td></tr>'
}
results += '</table><br /><br /><br />'
today = new Date().toTimestamp()
results +='<br /><small> Date my report : '+today+'</small>'
results += '</body></html>'
sendEmail('my_mailbox@gmail.com',results)
return results
def getIssues(jql)
{
resultIssues = []
int start = 0
int get = 100
searchService = ComponentAccessor.getComponent(SearchService.class)
user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issueManager = ComponentAccessor.getIssueManager()
parseResult = searchService.parseQuery(user, jql)
exist = true
while (exist)
{
pageFilter = new PagerFilter(start, get)
searchResult = searchService.search(user, parseResult.getQuery(), pageFilter)
issues = searchResult.results.collect {issueManager.getIssueObject(it.id)}
if (!issues) { exist = false }
resultIssues += issues;
start += get;
println "TEST recieved " + resultIssues.size() + " issues for $jql"
}
return resultIssues
}
def sendEmail(emailAddr, subject, body) {
mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer();
if (mailServer) {
Email email = new Email(emailAddr);
email.setSubject(subject);
email.setBody(body);
email.addHeader('Content-Type','text/html')
mailServer.send(email);
}
else {
// Problem getting the mail server from JIRA configuration, log this error
}
}
So, uhm, age old question. What doesn't work?
@Radek Dostál
I rewrote the code, now I receive a message in the mail, but without results with jql
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.bc.issue.search.SearchService;
import com.atlassian.jira.web.bean.PagerFilter;
import com.atlassian.mail.Email;
issueManager = ComponentAccessor.getIssueManager();
customFieldManager = ComponentAccessor.getCustomFieldManager();
regprov_sla = customFieldManager.getCustomFieldObjectByName("SLA_US_Reaction");
// Body
results = '<html><body><h3>Report</h3><br>'
results += '<b> Report project : REGPROV</b>.<br />'
results += '<table><tr><th>Assignee</th><th>Average task completion time</th><th>Amount ticket</th></tr>'
jql = 'project = REGPROV AND status = Closed AND resolved >= startOfWeek() AND assignee in (a.emelyanenko,e.povaga)'
issues = getIssues(jql)
results += '</table><br /><br /><br />'
today = new Date().toTimestamp()
results +='<br /><small>\DATE REPORT: '+today+'</small>'
results += '</body></html>'
sendEmail('My_mailbox@gmail.com','REPORT', results)
return results
def getIssues(jql)
{
resultIssues = []
int start = 0
int get = 100
searchService = ComponentAccessor.getComponent(SearchService.class)
user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issueManager = ComponentAccessor.getIssueManager()
parseResult = searchService.parseQuery(user, jql)
exist = true
while (exist)
{
pageFilter = new PagerFilter(start, get)
searchResult = searchService.search(user, parseResult.getQuery(), pageFilter)
issues = searchResult.results.collect {issueManager.getIssueObject(it.id)}
if (!issues) { exist = false }
resultIssues += issues;
start += get;
println "TEST recieved " + resultIssues.size() + " issues for $jql"
}
return resultIssues
}
def sendEmail(emailAddr, subject, body) {
mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer();
if (mailServer) {
Email email = new Email(emailAddr);
email.setSubject(subject);
email.setBody(body);
email.addHeader('Content-Type','text/html')
mailServer.send(email);
} else {
// Problem getting the mail server from JIRA configuration, log this error
}
}
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.
It doesn't seem to me that you're using the issues in any way:
issues = getIssues(jql)
results += '</table><br /><br /><br />'
today = new Date().toTimestamp()
results +='<br /><small>\DATE REPORT: '+today+'</small>'
results += '</body></html>'
sendEmail('My_mailbox@gmail.com','REPORT', results)
That 'issues' variable appears unused. There is no for loop to construct the cell data from it.
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.