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!
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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()
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am afraid there is no documentation. You just try to restrict your comment to a group and check what is returned.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.