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

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

Counting external comments when commenting on transition screen

I have created a listener that counts external comments, but it does not count comments created in a transition screen. The listener gets triggered, but it seems that the comment is added after the listener is triggered.

//Count numbers of external comments
int externalCommentCount = 0
def commentManager = ComponentAccessor.getCommentManager()
def commentPropertyService = ComponentAccessor.getComponent(CommentPropertyService)

def comments = commentManager.getComments(event.getIssue())
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

comments.each { Comment comment ->
def commentProperty = commentPropertyService.getProperty(user,, "sd.public.comment").getEntityProperty().getOrNull()
if (commentProperty) {
def props = new JsonSlurper().parseText(commentProperty.getValue())
if (!props['internal'] || props['internal'] == 'false') {
externalCommentCount = externalCommentCount + 1

CustomFieldManager customFieldManager = ComponentAccessor.getComponent(CustomFieldManager)
Collection externalCommentsCountField = customFieldManager.getCustomFieldObjectsByName("External Comments Count")
def value = event.getIssue().getCustomFieldValue(externalCommentsCountField[0])
if (value != externalCommentCount) {
DefaultIssueChangeHolder changeHolder = new DefaultIssueChangeHolder()
externalCommentsCountField[0].updateValue(null, event.getIssue(), (Double) externalCommentCount, changeHolder)

If is update the issue afterwards, the comment added through the transition screen , gets added as a +1.

0 answers

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

Admins, notify your Jira instance of system-wide changes with the new admin announcement banner

Hi All! We’re excited to share the launch of an announcement banner that lets Jira site administrators communicate directly to their users across their  Jira Cloud instance.  ...

694 views 17 19
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