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: 

Why is JQL result not coming?

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 5, 2022

Hi Community – I have a question for all you experts 😊

with jql you need to get such a result, but I have problems with this

efwE.png

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
}
}

 

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Samuel Gatica _ServiceRocket_
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 5, 2022

Hi @Alex 

 

Have you confirmed you get any data from the UI using the same JQL?

project = REGPROV AND status = Closed AND resolved >= startOfWeek() AND assignee in (a.emelyanenko,e.povaga)

 

Regards

Sam

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 5, 2022
TAGS
AUG Leaders

Atlassian Community Events