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

Scriptrunner - Last comment date for a public comment

Hi, 

How do I get the last comment date for a public comment only? 

Right now, I am using this script I found here, but it doesn't take into account whether the comment is public or private. I want to get the last comment date for a public comment only. 

import com.atlassian.jira.ComponentManager

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.component.ComponentAccessor

def commentManager = ComponentAccessor.getCommentManager()
def comment = commentManager.getLastComment (issue)
def date = comment.getCreated()

return (date)

Thank you!

1 answer

1 accepted

1 vote
Answer accepted

Hello,

What do you mean by public and private comment? Do you mean share with customer comment and internal comment in Jira Service Desk?

Hi Alexey, 

Yes, something like that. We have comments shared with the customer/client (public) and some are restricted to an internal group only (private), for example, a developer group. 

Thank you. 

I guess you are not using Jira Service Desk and private means that the comment was set either role or group visibility. In this case your code would look like this

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.component.ComponentAccessor
import java.util.Comparator;

defdef commentManager = ComponentAccessor.getCommentManager()
def commentList = commentManager.getComments(issue).sort{it.getCreated()}
Collections.reverse(commentList)
commentList.each{
 
    if (it.getRoleLevelId() == null && it.getGroupLevel() == null) {
      return it.getCreated()
    }
}

Hi Alexey, 

Sorry, yes, we are not using Jira service desk, just Jira software. 

I tried your code but I am getting an error message on this line - 

commentList.each{

 [Static type checking] - Cannot return value of type java.util.List <com.atlassian.jira.issue.comments.Comment> on method returning type java.util.Date

I am using the Date Time Picker template. 

Sorry, I am not familiar with Scriptrunner at all. 

Thank you for all your help. 

Could you try like this?

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.component.ComponentAccessor
import java.util.Comparator;

def commentManager = ComponentAccessor.getCommentManager()
def commentList = commentManager.getComments(issue).sort{it.getCreated()}
Collections.reverse(commentList)
for (Comment comment : commentList) {
if (comment.getRoleLevelId() == null && comment.getGroupLevel() == null) {
return comment.getCreated()
}
}
return null

It worked! Thank you so much, Alexey. :)

Hi Alexey, 

What are the values that this command  return?

comment.getGroupLevel()

 Is there a documentation where I can check these values? 

Thank you so much.

I am afraid there is no documentation. You just try to restrict your comment to a group and check what is returned.

Hi Alexey,

Is there a way to display the last internal comment? I'm using the following script but it does not filter out customer comments.

 

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager

import com.atlassian.jira.component.ComponentAccessor

def commentManager = ComponentAccessor.getCommentManager()

def comment = commentManager.getLastComment (issue)

if(comment != null)
{
" Author: " + comment.authorFullName + " - " + comment.getCreated() + "<br>" + comment.body
}

 

comment.getGroupLevel() == "Service Desk Team"

Check to see if the above condition would work. Service Desk Team would be your service desk agent access group.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

375 views 1 3
Join discussion

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