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,297,144
Community Members
 
Community Events
165
Community Groups

Filter or sort Comments by type?

I have a JSM project admin that's looking to filter/sort their comments panel by internal vs external comments - so they can view internal comments only when looking at an issue.

The issues on this project often get alot of comment traffic, mostly external comments as folks within the request participants discuss the issue - but the service desk team wants to be able to quickly review what work has been done on the issue internally. They're hoping for a way to view the internal comments only without having to scroll through all the comments.

We're considering using a custom field to display the last internal comment or last few internal comments - but wondering if there's any other solutions out there to modify the comment panel itself?

Any other add-ons? Anyone done something similar using scripting?

Anyone aware of an open feature request for something similar with Atlassian so we can vote for it?

 

1 answer

Hi @Rachel Richardson

For your requirement, you could try using the ScriptRunner console with something like this:-

import com.atlassian.jira.bc.issue.comment.property.CommentPropertyService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.util.json.JSONObject
import groovy.json.JsonSlurper

def commentManager = ComponentAccessor.commentManager
def projectManager = ComponentAccessor.projectManager
def issueManager = ComponentAccessor.issueManager

def project = projectManager.getProjectByCurrentKey('SAMPLE')
def issues = issueManager.getIssueObjects(issueManager.getIssueIdsForProject(project.id))

def internalComment = [] as ArrayList<Comment>
def externalComment = [] as ArrayList<Comment>
def issue

issues.each {
issue = it as Issue
commentManager.getComments(issue).each { Comment comment ->
if (isInternal(comment)) {
internalComment.addAll(comment)
} else {
externalComment.addAll(comment)
}
}
commentManager.deleteCommentsForIssue(issue)
}

internalComment.each {
final def SD_PUBLIC_COMMENT = "sd.public.comment"
def properties = [(SD_PUBLIC_COMMENT): new JSONObject(["internal": true] as Map)]
commentManager.create(issue as Issue, it.authorApplicationUser, it.body, null, null, new Date(), properties, true)
}

externalComment.each {
commentManager.create(issue as Issue, it.authorApplicationUser, it.body, null, null, new Date(), true)
}

static def isInternal(Comment comment) {
def SD_PUBLIC_COMMENT = "sd.public.comment"
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def commentPropertyService = ComponentAccessor.getComponent(CommentPropertyService)
def commentProperty = commentPropertyService.getProperty(loggedInUser, comment.id, SD_PUBLIC_COMMENT).entityProperty.orNull
if (commentProperty) {
def props = new JsonSlurper().parseText(commentProperty.value)
Boolean.parseBoolean(props['internal'].toString())
}
else {
null
}
}

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 configuration:-

configuration.png

The main line of code that controls the display of the internal comments is:-

commentManager.create(issue as Issue, it.authorApplicationUser, it.body, null, null, new Date(), properties, true)

 and this:-

commentManager.create(issue as Issue, it.authorApplicationUser, it.body, null, null, new Date(), properties, true)

for the external comments.

And the main section in the code above that needs to be modified to enable the sorting is the new Date() object.

If it is to be set to the original comment creation date like:-

commentManager.create(issue as Issue, it.authorApplicationUser, it.body, null, null, it.created, properties, true)

and 

commentManager.create(issue as Issue, it.authorApplicationUser, it.body, null, null, it.created, true)

it will not get sorted, i.e. sorting the comments is not doable if you want the original date to be maintained.

Hence, the new Date() object is declared.

Below are a few test screenshots:-

1. Before the script is executed:-

before.png

 

2. After the script has been executed:-

after.png

 

 

I hope this helps to answer your question. :)

Thank you and Kind regards,

Ram

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Service Management

Jira Service Management Documentation Opportunities

Hello everyone, Hope everyone is safe! A few months ago we posted an article sharing all the new articles and documentation that we, the AMER Jira Service Management team created. As mentioned ...

338 views 0 10
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