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,360,942
Community Members
 
Community Events
168
Community Groups

Why is JQL result not coming?

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

Hi @Oliver Smith 

 

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Management

An unofficial way to monitor a JSM mail handler for errors

...eturns true if any content is returned for the webResponse.body.data.first s...

682 views 3 20
Read article

Atlassian Community Events