You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
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?
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:-
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:-
2. After the script has been executed:-
I hope this helps to answer your question. :)
Thank you and Kind regards,
Ram
Does this answer your question?
If yes, please accept the answer.
Thank you and Kind regards,
Ram
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.