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
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}
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.