Scriptrunner post-function custom email template - Linked issue mentioned in Email template

Marco June 22, 2022

Hi atlassian community, 

we would like to send a custom notification to a customer when a specific transition was triggered. We have now several postfunctions working,  the first one is a script runner post function cloning the contents of the issue to a new issuetype and linking it to the issue. 

The second function should send a notificiation mail, that the issue is being moved to the issue XX-XXX. The template is working fine, but I have no idea on how to mention the newly created linked issue within the customer notification. 

 

Has somebody solved a related issue?

Edit: 

I found a function that maybe helps, but still not idea how to put that correct within the email template:

issueFunction in linkedIssuesOf("status = Open", "blocks") and resolution is empty

 

1 answer

1 accepted

0 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 25, 2022

You don't need to use the JQL. That's a bit round-about.

You just need to use the issueLinkManager to find the linked issue.

In your "Condition and Configuration" box add the following

def linkedIssues = issueLinkManager.getLinkCollectionOverrideSecurity(issue).allIssues
if(!linkedIssues){
//this will skip the execution of the send mail post function since no linked issue were found
//it probably means something when wrong in your earlier postfunction to create the linked issue
return false
}

config.lastLinkedIssueKey = linkedIssues.last().key

//make sure the condition returns true to trigger the rest of the send mail postfunction
return true

 

Then, in your Email Template, you can include any parameters added to "config"

Here is the body of your email
Where you might want to include ${config.lastLinkedIssueKey}

If you don't want to just blindly return the last linked issue, you can examine the information you get from getLinkCollectionOverrideSecurity() and filter by link type. Or examine the full list of issues and filter by status or other attributes.

E.g 

//only get the linked issues wihtout resolution
def filteresLinkedIssues = linkedIssues.findAll{ !it.resolution}
//only get the linked issues with status filer
def filteresLinkedIssues = linkedIssues.findAll{ it.status.name=='Open'}
//filter based on link type... you might want to look at getInwardLinks instead
def blockers = issueLinkManager.getLinkCollectionOverrideSecurity(issue).getOutwardIssues('Blockers')
Marco November 2, 2022

Thanks for your example. It works perfectly :)

Suggest an answer

Log in or Sign up to answer