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

Counting external comments when commenting on transition screen

Brian Michelsen May 27, 2019

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, comment.id, "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
TAGS
AUG Leaders

Atlassian Community Events