It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Scripted field - last unrestricted comment date but only if user is in certain a group Edited

Kenadit Shegow Apr 19, 2019

Hi all,

we are using the following scripted field to get the date of the last unrestricted comment:

 

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

 

Additionally, we would like for this script to only return a date if the user who added the comment is in a certain group. Is this possible?

Thank you for your assistance.

Best regards

2 answers

1 accepted

1 vote
Answer accepted
Wade Tracy [Boise, ID] Community Leader Apr 19, 2019 • edited

I'm not in a position to actually test the code at the moment, but it should be possible.  Comment can return the ApplicationUser that authored the comment.  Then you just need to create a GroupManager the same way you created the CommentManager.  GroupManager has a function for determining if a user is in a group.  It would look something like this:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.security.groups.GroupManager
import com.atlassian.jira.component.ComponentAccessor
import java.util.Comparator;

def commentManager = ComponentAccessor.getCommentManager()
def groupManager = ComponentAccessor.getGroupManager()
def commentList = commentManager.getComments(issue).sort{it.getCreated()}
Collections.reverse(commentList)
for (Comment comment : commentList) {
if (comment.getRoleLevelId() == null &&
comment.getGroupLevel() == null &&
groupManager.isUserInGroup(comment.getAuthorApplicationUser(), 'Group Name')) {

return comment.getCreated()
}
}
return null

 

 Hope that helps!

Kenadit Shegow Apr 23, 2019

Thank you Wade. This worked without any issues.

Kenadit Shegow Apr 23, 2019 • edited

Hi Wade,

please ignore the other notifications, I was able to resolve the other issues I had using the correct searcher for the field. In this case Date Time Range Picker.

1 vote
Peter-Dave Sheehan Apr 19, 2019 • edited

For that, you will want to use GroupManager

[...]
def groupManager = ComponentAccessor.groupManager
def group = groupManager.getGroup("name of your group")
[...]
if (comment.getRoleLevelId() == null && comment.getGroupLevel() == null) {
if(groupManager.isUserInGroup(comment.authorApplicationUser, group)) {
return comment.getCreated()
}
}


Peter-Dave Sheehan Apr 19, 2019

Found and corrected a typo  

comment.authorApplicationUser was comment.authorApplicatioUser

Peter-Dave Sheehan Apr 19, 2019

Also, the other signature of isUserInGroup(ApplicationUser, String groupName) as suggested by Wade will work. 

Kenadit Shegow Apr 23, 2019

thank you Peter

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Jira

Try Jira Cloud for Outlook: Organize your work without leaving your inbox

Hi Atlassian community, My name is Max and I work on the product integration team at Atlassian. I am pleased to announce the early access program for the Jira Cloud add-in for Outlook. This add-in...

2,008 views 6 15
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you