Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,551,670
Community Members
 
Community Events
184
Community Groups

Link Issue mentioned in Jira comment with Scriptrunner Listener

Hey All,

I'm looking for some scripting help with a Scriptrunner Listener script. I'm in need of a full listener script that will create an issue link when an issue is mentioned in the comments of the current issue. 

I found another article but it was a snippet of the script and some of the groovy wasn't valid. 

Any help and/or guidance would be greatly appreciated.

Cheers!

1 answer

1 accepted

0 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 07, 2023 • edited

Hi @Norm Moore

For your requirement, you can try something like this:-

import com.adaptavist.hapi.jira.issues.Issues
import com.atlassian.jira.issue.MutableIssue
import org.apache.commons.lang3.StringUtils

def issue = event.issue as MutableIssue
def lastComment = issue.comments.last()
def resultBuilder = new StringBuilder()

if (lastComment.body.contains("${issue.projectObject.key}-")) {
def filter1 = issue.projectObject.key.charAt(0)
def filter2 = StringUtils.substringAfter(lastComment.body,"${filter1}").split("\\s+")
resultBuilder.append(filter1).append(filter2.first())
}

def linkedIssue = Issues.getByKey(resultBuilder.toString())
issue.link('blocks', linkedIssue)

Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a screenshot of the Listener Configuration:-

listener_config.png

For the sample code above to work, please ensure you have updated your ScriptRunner plugin to the latest release, i.e. 8.0.0.

With the latest release, you will be able to make use of ScriptRunner's HAPI feature, which helps to simplify the code.

Below are a couple of test screenshots for your reference:-

1. First, I added a comment and included an issue key. In the sample below, I have entered MOCK-2 for the issue key. I then click the add button.

image1.png

2. As expected, the MOCK-2 issue is added to the issue link.

image2.png

3. I then repeat the same test with issue MOCK-11.image3.png

 

4. As expected, the MOCK-11 issue is added to the issue link.image4.png

Note: Please ensure that you refresh the page after adding the comment to display the linked issue.

I hope this helps to answer your question. :-)

Thank you and Kind regards,

Ram 

@Ram Kumar Aravindakshan _Adaptavist_ 

Thank you very much! It works like a charm. 

I appreciate all the help and effort in the script. 

Norm

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.20.11
TAGS
AUG Leaders

Atlassian Community Events