I am referring to the script written down under the link -->
https://community.atlassian.com/t5/Jira-questions/Using-Jira-Script-Runner-s-Escalation-Service-to-send-an-email/qaq-p/871519
I wanted to send email for every issue result returned from the search query used. But it looks like the class or methods used is depreciated now, could some suggest alternate fetch option ?
The error description, please find the attached screen shot.
Thanks.
hey @Nagappan Murugappan ,
it could be the error doesn't really mean anything. I noticed you defined your array just as def and thus didn't specify a type that will go into ti.
I assume that below the code you loop through the issues?
if so the interpreter cannot find what the type is and thus not find a proper method. I would suggest to properly cast/define your variable first so your methods are found in those classes
Hi Dirk
Thanks for your reply.
I think the screen shot was hiding the code, here is the complete code. (from the link above)
import com.atlassian.mail.Emailimport com.atlassian.jira.bc.issue.search.SearchServiceimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.web.bean.PagerFilter
def issueManager = ComponentAccessor.getIssueManager()def searchService = ComponentAccessor.getComponent(SearchService)def jqlSearch = "project = foobar AND Updated < -2w AND resolution is empty AND status != Backlog ORDER BY status ASC"def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
// eventually this array will contain all the issues that returned from the JQLdef issues = []
// hashmap to store username and associated issue(s)
def map = [:].withDefault {[]} //The default value will be created every time a non-existing key is accessed.// Need this to be able to dynamically expand/update map
SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch)if (parseResult.isValid()) {def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())issues = searchResult.issues.collect { issueManager.getIssueObject(it.id) }}
// We are breaking out the issues per assignee. Will use later when we email the assigneesissues.each {def assignee = it.assigneeId
map[assignee].add(it)
}
// following section creates separate emails for each assignee from the map, including all related issues in the same email.
map.each { key, value ->def assignee = keydef theirIssues = value as List
def assigneeEmail = ""String cc = "someguy@somedomain.com"String bcc = ""
def body = "The following issues not been updated in over two weeks. " +"Please review and update your assigned issues with comments, updated status and (if available) a due date." +"<br/><br/>" +"<table>\n" +" <tr>\n" +" <th>Issuekey</th>\n" +" <th>Summary</th>\n" +" <th>Assignee</th>\n" +" </tr>"
theirIssues.each {
assigneeEmail = it.assignee.emailAddress
body += " <tr>\n" +" <td><a href=\"https://somejirainstance.com/browse/${it.key}\">${it.key} </a></td>\n" +" <td>${it.getSummary()}</td>\n" +" <td>${it.assigneeId}</td>\n" +" </tr>"}
body += "</table>\n" +"\n" +"<br></br>\n" +"Regards, <br></br>\n" +"\n" +"Jira Automation"
sendEmail(assigneeEmail, cc, bcc, "The following issues need your assistance", body)
// Create an emaildef sendEmail(String emailAddr, String cc, String bcc, String subject, String body ) {def mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer()if (mailServer) {def email = new Email(emailAddr)email.setMimeType("text/html")email.setSubject(subject)email.setBody(body)email.setCc(cc)email.setBcc(bcc)mailServer.send(email)log.debug("Mail sent")} else {log.warn("Please make sure that a valid mailServer is configured")}}
Hmm so seems the line(s) that are giving you issues are:
def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())issues = searchResult.issues.collect { issueManager.getIssueObject(it.id) }
Could you clarify if you are using Cloud or Server? I'm a bit confused about that.. and if Server what version?
Yes, you are the correct, that's where the error appears.
I am using cloud version -
Hi Nagappan,
I can confirm version 8.13.1 is a Jira Server version and your screenshots show your code is from Jira Server.
You will only be using Jira Cloud if your instance URL ends in .atlassian.net.
Regards,
Kristian
@Kristian Walker _Adaptavist_ Thanks for your support, it was very helpful.
It looks like you're new here. Sign in or register to get started.