Script Fields - get the date of the last unrestricted comment

Ken April 17, 2019

Hi all,

I created a custom script field and would like for it to output the date of the last unrestricted comment. In the community, I found some scripts, but those don't take into account whether the comment is public or private.

The reason for this is that we have a lot of restricted comments to groups and the default updated field is always updated for any issue updated events, so we would like to have a field where we can see when the last communication (unrestricted all users) took place.

 

Our scriptrunner version is 3.1.4 .

 

Thank you for the assistance.

 

Best regards

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.
April 17, 2019

Restricted comment gets applied either a "RoleLevel" or a "GroupLevel" based on what type of restriction was applied.

Looking at the API documentation for Comment, you can see that there is a "getRoleLevel" and "getGroupLevel" methods.

 

So, when you get the comments for your issue, you can just filter out all the restricted ones (both roleLevel and groupLevel will be null ).

def unrestrictedComments = ComponentAccessor.commentManager.getComments(issue).findAll{!it.roleLevel && !it.groupLevel}
Ken April 19, 2019

Thanks Peter. Regarding the date format I found another helpful community solution: https://community.atlassian.com/t5/Adaptavist-questions/Date-format-for-script-field/qaq-p/698130

 

The final resolution for me was the following configuration:

Template: "Custom"

 

Custom Template:

$datePickerFormatter.withStyle($dateTimeStyle.DATE).format($value)

 

Inline Script:

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) {
def date = comment.getCreated()
return date
}
}
return null

 

Suggest an answer

Log in or Sign up to answer