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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,553,564
Community Members
 
Community Events
184
Community Groups

How to fetch comment visibility in Scriptrunner?

In Scriptrunner, I am trying to create a Scripted Field for a Jira Service Management project.

The field will be fetching the date of the last public comment that was made by a user who is a member of a specific group.

Basically, I want to check if that comment is public or internal but I cannot get this information from the comment (com.atlassian.jira.issue.comments.CommentImpl)

I found this article by Adaptavist but I cannot adjust it in my script:

https://library.adaptavist.com/entity/get-the-visibility-of-new-comments-in-jira-service-desk

Any help on how to get the comment visibility and adjust it to the script below will be much appreciated:

 

import com.atlassian.jira.component.ComponentAccessor

def commentManager = ComponentAccessor.commentManager

def comments = commentManager.getComments(issue).reverse()

def lastCommentDate = null

def groupX = ComponentAccessor.groupManager.getGroup("group-x")

for (comment in comments){

    def author = comment.authorApplicationUser.username

   

    // Here, I want to check if the comment is public or internal

    if (ComponentAccessor.groupManager.getUserNamesInGroup(groupX).contains(author)) {

        lastCommentDate = comment.updated

        break;

    }    

}

if(lastCommentDate)

    return lastCommentDate

1 answer

1 accepted

1 vote
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Dec 16, 2021

There are some references in the scriptrunner documentation pages and the Adaptavist library for that:

 

In short, you need to look at the properties of the comment:

def commentPropertyService = ComponentAccessor.getComponent(CommentPropertyService)
final def
SD_PUBLIC_COMMENT = "sd.public.comment"

def isInternal = { Comment c ->
def commentProperty = commentPropertyService.getProperty(user, c.id, SD_PUBLIC_COMMENT)
.getEntityProperty().getOrNull()
if (commentProperty) {
def props = new JsonSlurper().parseText(commentProperty.getValue())
props['internal']?.toBoolean()
} else {
null
}
}

Thanks, Peter, I had to adjust it a bit by following the first article you've shared and it worked.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
4.20.0
TAGS
AUG Leaders

Atlassian Community Events