Hello,
currently i´m trying to get Jira to show me the number of internal comments in each issue. I tried running scriptrunner and entered a code for the general comment count (internal and external).
However it doesn´t work, can someone please point out the mistake and maybe show also the way for internal comments.
import com.blablub.jira.component.ComponentAccessor
def commentManager = ComponentAccessor.getCommentManager()
def comments = commentManager.getComments(issue)
if (comments) {
comments.last().updated
}
Thanks ;)
Hello,
Have a look at the post below. You can see how to define if a comment is internal or not. Then you can count internal comments
The required line is
def isInternal = { Comment c -> def commentProperty = commentPropertyService.getProperty(user, c.id, SD_PUBLIC_COMMENT) .getEntityProperty().getOrNull() if (commentProperty) { def props = new JsonSlurper().parseText(commentProperty.getValue()) props['internal'].toBoolean() } else { null } }
Hey Alexey,
I just tried the lines you shared but it doesn´t work.
Following errors appear: unable to resolve class Comment in line 1, column 18.
and unable to resolve class JsonSlurper in line 6, column 21.
Isn´t there a way to get the number of internal comments with the script of Nic?
For example, instead of comments.size() it would be something like internalcomments.size ().. ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
THe code would be like this. Change IssueKey to your issue key
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.Comment
import groovy.json.JsonSlurper
import com.atlassian.jira.bc.issue.comment.property.CommentPropertyService
final SD_PUBLIC_COMMENT = "sd.public.comment"
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def commentPropertyService = ComponentAccessor.getComponent(CommentPropertyService)
def isInternal = { Comment c ->
def commentProperty = commentPropertyService.getProperty(user, c.id, SD_PUBLIC_COMMENT)
.getEntityProperty().getOrNull()
if (commentProperty) {
def props = new JsonSlurper().parseText(commentProperty.getValue())
if (props['internal']) {
true
} else {false}
}
else {
null
}
}
def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("IssueKey");
log.error(ComponentAccessor.getCommentManager().getComments(issue).findAll{isInternal(it)}.size());
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Go to issue detail view and there will be project key then "-" and then number.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hmm i´m not sure why, but this code does not work for me. Jira doesn´t show any error but when I do a search, no results are shown for internal comments.
For example when I search for an issue which has 30 comments, it says 30 comments (with the code from Nic), but the internal comments field is empty, not even a 0 is shown.
In the Scripts Field it says 15 of 15 failed, including the last one.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I guess you have a scripted field. Then try like this
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.Comment
import groovy.json.JsonSlurper
import com.atlassian.jira.bc.issue.comment.property.CommentPropertyService
final SD_PUBLIC_COMMENT = "sd.public.comment"
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def commentPropertyService = ComponentAccessor.getComponent(CommentPropertyService)
def isInternal = { Comment c ->
def commentProperty = commentPropertyService.getProperty(user, c.id, SD_PUBLIC_COMMENT)
.getEntityProperty().getOrNull()
if (commentProperty) {
def props = new JsonSlurper().parseText(commentProperty.getValue())
if (props['internal']) {
true
} else {false}
}
else {
null
}
}
return ComponentAccessor.getCommentManager().getComments(issue).findAll{isInternal(it)}.size();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Alexey,
thanks for the code. We´re almost there.. It works well but i´m not sure why, but it shows strange results:
For example an issue has 20 comments in total. 10 of those are shown as internal. But from those 10 only 6 are really internal (literally written from people in this company and sent with the "Internal Comment" Button). The other 4 "internal" comments are just normal sent into the chat visible for customers and workers.
If that final problem would be fixed then the results should be just fine.
Has it got to do with this line maybe?
findAll{isInternal(it)}
Thanks for all your help! ;)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try like this
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.Comment
import groovy.json.JsonSlurper
import com.atlassian.jira.bc.issue.comment.property.CommentPropertyService
final SD_PUBLIC_COMMENT = "sd.public.comment"
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def commentPropertyService = ComponentAccessor.getComponent(CommentPropertyService)
def isInternal = { Comment c ->
def commentProperty = commentPropertyService.getProperty(user, c.id, SD_PUBLIC_COMMENT)
.getEntityProperty().getOrNull()
if (commentProperty) {
def props = new JsonSlurper().parseText(commentProperty.getValue())
if (props['internal']) {
true
} else {false}
}
else {
false
}
}
return ComponentAccessor.getCommentManager().getComments(issue).findAll{isInternal(it)}.size();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Alexey,
just one problem I found with this code. For some reason the result is always 1 comment too much. Like 10 comments, 5 are actually marked as internal but the result is shown as 6.
Is there a way to put a "-1" into the code?
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It would be better if you tried to define which comment is counted as wrong. But you can substract 1 to the result like this
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.Comment
import groovy.json.JsonSlurper
import com.atlassian.jira.bc.issue.comment.property.CommentPropertyService
final SD_PUBLIC_COMMENT = "sd.public.comment"
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def commentPropertyService = ComponentAccessor.getComponent(CommentPropertyService)
def isInternal = { Comment c ->
def commentProperty = commentPropertyService.getProperty(user, c.id, SD_PUBLIC_COMMENT)
.getEntityProperty().getOrNull()
if (commentProperty) {
def props = new JsonSlurper().parseText(commentProperty.getValue())
if (props['internal']) {
true
} else {false}
}
else {
false
}
}
return ComponentAccessor.getCommentManager().getComments(issue).findAll{isInternal(it)}.size() - 1;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, thats true its better to know the origin. I just tested a few tickets and saw that the first response also creates a comment as internal (even when I click on share with customer).
So there must be a way to ignore the first comment when opening a ticket and giving the comment to the customer (as it counts as internal for whatever reason).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So basically I need to know if its possible to change the following setting:
Where can I change the settings for first response comments?
At the moment it seems to be set to count as internal although everyone including customers can see it.
I would like to change that setting to external.
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For a count of the comments, try
comments.size()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried this, no errors are given but it still doesn´t work. It shows the normal count of comments of internal and external
import com.atlassian.jira.component.ComponentAccessor
def internalcommentManager = ComponentAccessor.getCommentManager()
def internalcomments = internalcommentManager.getComments(issue)
if (internalcomments) {
internalcomments.size()
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.