Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage


Hello ,
I want to run the following script every hour with the scriptrunner and send the mail with the url content, if the create time has not been assigned for 60 minutes and there are unresolved records. I can combine several scripts below and send mail. If there is no result, I want it not to send mail and the results returned in the mail content should return as urls. But I couldn't :) I would like your valuable help.


package dk.langhornweb
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.worklog.WorklogImpl
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.mail.Email
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.mail.server.SMTPMailServer
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def searchService = ComponentAccessor.getComponent(SearchService)
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def query = jqlQueryParser.parseQuery("PROJECT = zzz AND assignee is EMPTY AND status = Open AND resolution = Unresolved and created = -60m" )
def results =,query, PagerFilter.getUnlimitedFilter())
results = results.getResults().each() { print "${it.key}"}
def filterId = 15902
def sendToEmail = "zzzzzz@zzzzz.zzzz"
def jiraGroups = [""]
def jiraAuthContext = ComponentAccessor.getJiraAuthenticationContext()
def searchRequestManager = ComponentAccessor.getComponent(SearchRequestManager.class)
def searchRequest = searchRequestManager.getSearchRequestById(filterId)
def searchResult =, searchRequest.query, PagerFilter.unlimitedFilter)
if (searchResult.results.size() > 0) {
String cc = buildcc(sendToEmail, jiraGroups)
"| Atanmamış Kayıtlar Bulunmaktadır",
"Sayın Yönetici,\nEkibinizde atanmamış kayıtlar bulunmaktadır.\n\f$results\n\r Bu mail Yardım Masası tarafından Her gün saat 11:00'da otomatik olarak gönderilmektedir.")

// Build email cc
def buildcc(def defaultEmail, List<String> groups) {
def ccList = [""]
def groupManager = ComponentAccessor.getGroupManager()
groups.each { group ->
Collection<ApplicationUser> memberList = groupManager.getUsersInGroup(group)
memberList.each { member ->
return ccList.join(",")

// Create an email and send
def sendEmail(def emailAddr, def cc, def subject, def body) {
SMTPMailServer mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer()
if (mailServer) {
Email email = new Email(emailAddr as String)
email.setCc(cc as String)
email.setSubject(subject as String)
email.setBody(body as String)
log.debug("Mail sent")
} else {
log.warn("Please make sure that a valid mailServer is configured")

2 answers

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:

0 votes
Antoine Berry Community Leader Aug 03, 2020

Hi @Ufuk Uysal ,

Have you tried running this script, and have you found any error in the logs ? 

It seems you are not using the query in the script but rather the filter 15902. The mail will be sent if there this filters has results.

hi antoine,

this script is running. The filter id and jql above are the same. I want him to mail if the result is frozen. Even if there is no result, mail is sent as []. If there is a result, the url does not come as follows. How can I fix this situation?

[Documentıssueımpl [issuekey = INFRASTRUCTURE-202]

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Apps & Integrations

How we use Jira Service Management for our recruitment process! - Part 2

It is never about setting up a process and being done with it. Rather, the focus should always be on optimizing it for the best outcomes. Thus, we didn’t stop at setting up JSM for our recruitment pr...

184 views 0 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you