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
Community Members
Community Events
Community Groups

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

Atlassian Community Events