Missed Team ’24? Catch up on announcements here.

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

Filter or sort Comments by type?

Rachel Richardson
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 6, 2022

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

1 vote
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.
June 8, 2022

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

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.
July 6, 2022

Hi @Rachel Richardson,

 

Does this answer your question?

If yes, please accept the answer.

 

Thank you and Kind regards,

Ram

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events