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.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.issue.search.SearchQuery
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchRequestManager
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 = searchService.search(user,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 = searchService.search(user, searchRequest.query, PagerFilter.unlimitedFilter)
if (searchResult.results.size() > 0) {
String cc = buildcc(sendToEmail, jiraGroups)
sendEmail(sendToEmail,
cc,
"| 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 = ["xxxx@xxx.xxx"]
def groupManager = ComponentAccessor.getGroupManager()
groups.each { group ->
Collection<ApplicationUser> memberList = groupManager.getUsersInGroup(group)
memberList.each { member ->
ccList.add(member.getEmailAddress())
}
}
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)
mailServer.send(email)
log.debug("Mail sent")
} else {
log.warn("Please make sure that a valid mailServer is configured")
}
}
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.