how to get the key of a linked issue in the email body when you use "Send custom email" script post-function

mel vega March 2, 2016

Hi,

I want to use a "send custom email" post-function with script runner. In the body of my email, I would like to get the issue key of eventual linked issue.

Any ideas please ?

Thanks

Melissa

3 answers

1 vote
Guy Anela January 3, 2018

I used the following code in the "Email template" section. It loops through the Linked Issues and builds out a list of linked issues (Please excuse the code as I don't claim to be a developer by any means :)).

I hope this helps.  ...Cheers!

 <b>Linked Issues:</b> <br>

<ul>
<%

def outwardlinks = com.atlassian.jira.component.ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId())
def inwardlinks = com.atlassian.jira.component.ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId())
def oCounter=0
def iCounter=0


// Check for Outward Links...
if (outwardlinks)

for (id in outwardlinks) {
def linkedissueKey = com.atlassian.jira.component.ComponentAccessor.getIssueManager().getIssueObject(outwardlinks[oCounter].destinationId).key
def linkedissueSummary = com.atlassian.jira.component.ComponentAccessor.getIssueManager().getIssueObject(outwardlinks[oCounter].destinationId).summary
def linkedissueStatus = com.atlassian.jira.component.ComponentAccessor.getIssueManager().getIssueObject(outwardlinks[oCounter].destinationId).status.name

out << "<li><a href='https://jira.domain.com/browse/"+linkedissueKey+"'>"+linkedissueKey+"</a> "
out << "("+linkedissueStatus+"):"
out << linkedissueSummary+"</li><br>"

oCounter ++
}


// Check for Inward Links...
if (inwardlinks)

for (id in inwardlinks) {
def linkedissueKey = com.atlassian.jira.component.ComponentAccessor.getIssueManager().getIssueObject(inwardlinks[iCounter].sourceId).key
def linkedissueSummary = com.atlassian.jira.component.ComponentAccessor.getIssueManager().getIssueObject(inwardlinks[iCounter].sourceId).summary
def linkedissueStatus = com.atlassian.jira.component.ComponentAccessor.getIssueManager().getIssueObject(inwardlinks[iCounter].sourceId).status.name

out << "<li><a href='https://jira.domain.com/browse/"+linkedissueKey+"'>"+linkedissueKey+"</a> "
out << "("+linkedissueStatus+"):"
out << linkedissueSummary+"</li><br>"


iCounter ++
}

%>

</ul>

 

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 2, 2016

What does "eventual linked issue" actually mean? This can be quite complex.

0 votes
Vasiliy Zverev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 2, 2016

You can get all linked issues like this

ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId())
mel vega March 3, 2016

Hi both, @Jamie Echlin [Adaptavist] @Vasiliy Zverev

 

thanks for your answer. Do not pay attention to the "eventual" liked issues. sorry it was confusing and does not matter.

here is my email and what I tried to show the linked issue reference thanks to Vasiliy's comment: (send custom email post-function script). But it returned into a script error. Any ideas? thanks for your help

 

 

<p>Dear all,</p>

<p>For your information, this NPC study has been reviewed with your teams. Please find attached the detailed Impact Analysis.</p> <p>You can also log in directly our tool JIRA: <a> "https://aptp-alm.accenture.com/jira/browse/$issue.key"</a></p>

<p>Summary: ${issue.summary}</p>

 <p>Description: ${issue.description}*</p>

<p>SCOPE restriction:</p>

 <p>CAP volume:</p>

<p>First trade planned:</p>

<p>IT development:</p>

<p><% out << issue.getCustomFieldValue(componentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId())%></p>

<p>Best Regards,</p>

<p>NPC team

 

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 6, 2016

Can you remove the "issue.getCustomFieldValue", not sure why you have that.

Suggest an answer

Log in or Sign up to answer