I'm having script runner send an email. I want the email to list and provide links to any issues linked to the JIRA that is running the script. The query to find all issues linked is 'issueFunction in linkedIssuesOf("issue = <issue>") ' However, if I put that in the template, it just spits that out in plain text and doesn't actually query for results. I'm not experienced in email templates unfortunately. How would I make that query executable?
Hi Jeff
So, if I understand well you want to send an email (either via a listener or a post function) with all the linked issues to the 'original' issue. Below is a script that concat in a string all the linked issues (and not the subtasks like the jql does).
You need to use the "currentUser" binding when your in a post-function, as looking it up from the authentication context returns null.
<% //code goes here def issueLinkManager = com.atlassian.jira.component.ComponentAccessor.getIssueLinkManager() def linkCollection = issueLinkManager?.getLinkCollection(issue, currentUser) //collect all issues in a list def allLinkedIssues = linkCollection?.getAllIssues() //concat all issues links in a string def linkedIssues = allLinkedIssues.collect {issue -> '<a href="<yourBaseUrl>/jira/browse/' + issue.key + '">' + issue.key + '</a>' }.join("<br>") %> Linked issues : <br> $linkedIssues
If your email format is HTML you will get something like that (Tested in JIRA v6.4.7)
preview-screenshot.png
If you however you want to go with the jql search
<% //code goes here def issueManager = com.atlassian.jira.component.ComponentAccessor.getIssueManager() def searchService = com.atlassian.jira.component.ComponentAccessor.getComponent( com.atlassian.jira.bc.issue.search.SearchService) //jql search for the current issue key def jqlSearch = 'issueFunction in linkedIssuesOf("issue = ' + issue.key + '")' def parseResult = searchService.parseQuery(currentUser, jqlSearch) def allLinkedIssues = [] if (parseResult.isValid()) { def searchResult = searchService.search(currentUser, parseResult.getQuery(), com.atlassian.jira.web.bean.PagerFilter.getUnlimitedFilter()) allLinkedIssues = searchResult.issues.collect { issueManager.getIssueObject(it.id) } } //collect all issues in a list //concat all issues links in a string def linkedIssues = "<br>" for (def issue in allLinkedIssues) { linkedIssues = linkedIssues + '<a href="<yourBaseUrl>/jira/browse/' + issue.key + '">' + issue.key + '</a><br>' } %> Linked issues : $linkedIssues
Hi Thanos! Yes, that is exactly what I'm trying to do. However, I can't seem to get it working. I'm running 6.4 currently. Here's what the email template looks like in my post function.
<% //code goes here def User = com.atlassian.jira.component.ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() def issueLinkManager = com.atlassian.jira.component.ComponentAccessor.getIssueLinkManager() def linkCollection = issueLinkManager?.getLinkCollection(issue, User) //collect all issues in a list def allLinkedIssues = linkCollection?.getAllIssues() //concat all issues links in a string def linkedIssues = "<br>" for (def issue in allLinkedIssues) { linkedIssues = linkedIssues + '<a href="tracker.redbrickhealth.local/jira/browse/' + issue.key + '">' + issue.key + '</a><br>' } %> Linked issues : $linkedIssues
The email I receive just shows
Linked issues :
There are no linked issues like in your example above, but that is exactly what I want. Did I change the user sections correctly?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Jeff,
Apologies for the delay. A colleague @Adam Markham [Adaptavist] pointed out thet instead of the def User = com.atlassian.jira.component.ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() you should use the currentUser
I updated the original answer above.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.