Forums

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

Scriptrunner Jira - Custom scheduled job - Run JQL & Email all Assignees

Richard Duffy
Contributor
August 3, 2020

Hi

App - Scriptrunner for Jira

Function - Custom scheduled Job (cronjob)

Usercase - Run a JQL query, retrieve the results and send email to all assignee of tickets

The below code does get me the usernames from my jql filter, but i need the email address to use.

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchException
import com.atlassian.jira.web.bean.PagerFilter
import org.apache.log4j.Level


import com.atlassian.jira.mail.Email
import com.atlassian.jira.mail.settings.MailSettings
import com.atlassian.mail.MailException
import org.apache.log4j.Logger




// Set log level to INFO
log.setLevel(Level.INFO)

// The JQL query you want to search with
final jqlSearch = "project = SDPTS AND summary ~ test"

// Some components
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def searchService = ComponentAccessor.getComponentOfType(SearchService)

// Parse the query
def parseResult = searchService.parseQuery(user, jqlSearch)
if (!parseResult.isValid()) {
log.error('Invalid query')
return null
}

try {
// Perform the query to get the issues
def results = searchService.search(user, parseResult.query, PagerFilter.unlimitedFilter)
def issues = results.results
issues.each {
log.info(it.key)
}

issues*.assignee
} catch (SearchException e) {
e.printStackTrace()
null
}

 

Thanks

Rich

1 answer

0 votes
Boris Berenberg - Atlas Authority
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 Leaders.
August 4, 2020

If you can't get this working in ScriptRunner, you may want to try our app which is built to support this UX from the ground up: https://marketplace.atlassian.com/apps/1211069/notification-assistant-for-jira-email

Richard Duffy
Contributor
August 4, 2020

Thanks Boris, Ill check it out. I was able to simplify the requirement and create a job to send mail to a Jira group, this may be an acceptable workaround.

Rich

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events