The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

How get number of issue from scriptrunner?

Alex
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 Champions.
September 6, 2022

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

TAGS
AUG Leaders

Atlassian Community Events