Forums

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

Populating Linked Issues In Email Templates.

Craig Nodwell
Community Champion
July 6, 2022

Question about getting the values for Linked issues into an email template post function.
I've tried a number of ways to populate this via a script (in the condition section) of a send email post function.  The script gives me the correct output in the script console but trying to get this out and into an email template is driving me NULL nuts.
Here's a piece of my script.

List<IssueLink> allOutIssueLink = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId());

for (Iterator<IssueLink> outIterator = allOutIssueLink.iterator(); outIterator.hasNext();) {

 IssueLink issueLink = (IssueLink) outIterator.next();

 def linkedIssue = issueLink.getDestinationObject()

 config.linkedIssue1 = linkedIssue.getKey(linkedIssue)

 String config.type = linkedIssue.getIssueType().getName();

String config.Outwardresults = linkedIssue.getIssueType().getName() + " " + linkedIssue.getKey() + " " + linkedIssue.getSummary() + "<br />"  // returns null works in console

config.outsnow = linkedIssue.getKey() // returns null

config.typer = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getID()) //linkedIssue.getKey() // returns null

config.putAll()

return true

Any help would be appreciated.  I've probably spent too much time looking at this now and need to walk away for a bit.  Again though any help would be appreciated.
Thanks
-CN

1 answer

1 accepted

0 votes
Answer accepted
Craig Nodwell
Community Champion
July 7, 2022

Well I found the answer myself :) Here's my code:

//Email Condition
import com.atlassian.jira.issue.link.RemoteIssueLinkManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.applinks.api.application.jira.JiraApplicationType
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.user.ApplicationUser
import com.opensymphony.workflow.loader.ActionDescriptor
import groovy.xml.MarkupBuilder
import com.atlassian.jira.config.properties.APKeys
import com.atlassian.jira.issue.link.LinkCollectionImpl;
import com.atlassian.jira.issue.link.IssueLink;
// Get the components
def issueManager = ComponentAccessor.issueManager
def issueLinkManager = ComponentAccessor.issueLinkManager
def remoteIssueLinkManager = ComponentAccessor.getComponent(RemoteIssueLinkManager)

// Get the issue links to other issues
def issueLinks = issueLinkManager.getOutwardLinks(issue.id)

// Collect the HTML links pointing to the linked issues
def baseUrl = ComponentAccessor.applicationProperties.getString(APKeys.JIRA_BASEURL)
def linkedIssuesHtmlLinks = issueLinks.collect { issueLink ->
    def issueUrl = "${baseUrl}/${issueLink.destinationObject.key}"
    "<a href='${issueUrl}'>This issue ${issueLink.issueLinkType.name} ${issueLink.destinationObject.issueType.name} ${issueLink.destinationObject.key} ${issueLink.destinationObject.summary} </a>"
}
// Collect the HTML links pointing to the remote links
def remoteLinks = remoteIssueLinkManager.getRemoteIssueLinksForIssue(issue)
def remoteLinksHtml = remoteLinks.collect { remoteLink ->
    "<a href='${remoteLink.url}'>${remoteLink.title}</a>"
}
def outputs = " "
//config.outputs allows us to pass the variables to the mail template
// Display the links
config.outputs ="""<p>Issue links:</p>
<ul>
    ${linkedIssuesHtmlLinks.collect { "<li>${it}</li>" }.join('\n')}
</ul>
<p>Remote links:</p>
<ul>
    ${remoteLinksHtml.collect { "<li>${it}</li>" }.join('\n')}
</ul>
"""
return true
/////////////////////////
Email Template
<p>The $issue.issueType.name $issue.key has been assigned to you for approval.</p>
<p><b>Description:</b></p>
<p>${issue.description.replaceAll('h3.',"</p><p>").replaceAll("\\*","</p><p>")}</p>
<p><b>System(s) Affected:</b>
<p><% out << issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("DevOps Systems"))%></p>
<p><b>Requirements:</b>
<p><% out << issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Requirements"))%></p>
<p><b>Links:</b>
<p>${config.outputs}</p>
<p>${getWorkflowButtons.call()}</p>

Suggest an answer

Log in or Sign up to answer