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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Get the Content of the Last Comment

Is it possible to create a script with "ScriptRunner" that runs a "JQL" and displays the last comment of the filtered issues?

2 answers

How would you expect JIRA to show this information?

Actually I would like to analyze the content of the last comment and check if I was mentioned there (@username). I would like to get a list of issues where I was mentioned in the last comment.

It sounds like you're looking to create a JQL function then? You'd like to write a query like issueFunction in mentionedInLatestComment(currentUser()) and be returned a list of issues that match this function?

Steven Behnke Community Leader Jul 21, 2017

You're looking for this ScriptRunner module: https://scriptrunner.adaptavist.com/latest/jira/custom-jql-functions.html

I have created JQL functions to search on Projects, Users, and Versions before, but I haven't tried to extract @mentions from comments.

You're likely going to need to use CommentManager.getLastComment(Issue issue) to obtain the last comment for each issue, then you can use Comment.getBody() to obtain the comment text. Finally, you can parse the content to search for the mention format, which is stored like this: [~username]. Once you extract this, you can compare the mentions to the argument passed to the JQL function.

Hi, 

I am trying to achieve the same.

  1. SR runs the JQL 
  2. Based on JQL return the last/array of issue key and last comment

Based on research I have code which gives me the issue keys but does not know how to add comments to this. Some errors I got referring to the arrays that could not be created.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.component.ComponentAccessor

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class)
def searchProvider = ComponentAccessor.getComponent(SearchProvider.class)
def customFieldManager = ComponentAccessor.customFieldManager
def issueManager = ComponentAccessor.issueManager
def commentManager = ComponentAccessor.getCommentManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def query = jqlQueryParser.parseQuery("project = XXX and labels = YYY")
def issue_results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())

def issueList = issue_results.issues.collect{issueManager.getIssueByCurrentKey(it.key,)}

issueList.each{
def issue = it as MutableIssue
}

If you could help I am thrilled.

Best,

Simon

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you