Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,363,261
Community Members
 
Community Events
168
Community Groups

How get number of issue from scriptrunner?

Edited

Hi all! Can you please tell me how to get the number of closed tasks separately for each user, and not the task numbers themselves?


My report only sends issues (REGPROV-1448 etc.) and not the number of closed issues per user

 

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() '
assignee_jql = ['a.emelyanenko','a.shafranova','o.gorbunova','d.kunitsyna','g.voytovich','e.povaga','a.avramenko','v.vorobeva']

issues = getIssues(jql)

for(assignee in assignee_jql){
jql2 = jql + ' AND assignee = "'+assignee+'"'
issues = getIssues(jql2)
Integer avh = 0
Integer count = 0
for (issue in issues){
sla_val = issue.getCustomFieldValue(regprov_sla);

println "TEST recieved $issue: handling $sla_val"
results += '<tr><td>'+issue+'</td><td></td><td></td></tr><tr><td>'+assignee+'</td><td></td><td></td></tr>'
}
}

results += '</table><br /><br /><br />'
today = new Date().toTimestamp()
results +='<br /><small> DATE REPORT: '+today+'</small>'
results += '</body></html>'

sendEmail('my_mail@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
}
}

УАЦУА.png

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events