Hello!
Is there a way to use script runner (or other plugins) in order to create a custom field which will calculate the number of comments containing specific text, that were added in a the last week?
Thanks!
Danielle
Quick mock up of what the logic would look like for this. Might be a few syntax errors since I haven't tested it, but it should be basically right.
import com.atlassian.jira.issue.comments.CommentManager
import java.util.GregorianCalendar
import java.util.Date
import java.util.Calendar
def comments = CommentManager.getComments(issue)
def count = 0
def textToCheck = "Text you want to check"
Calendar cal = new GregorianCalendar()
cal.add(Calendar.DAY_OF_MONTH, -7)
Date sevenDaysAgo = cal.getTime()
for (comment in comments)
{
def text = comment.getBody()
def created = comment.getCreated()
if (text.contains(textToCheck) && created > sevenDaysAgo)
{
count++
}
}
return count
@Ben Poulson @Antoine Berry Thanks again!
This is what I did and it's working perfectly (just counting the number of those specific comments):
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.component.ComponentAccessor
List<String> list = new ArrayList<String>();
def comments = ComponentAccessor.commentManager.getComments(issue)
def count = 0
def textToCheck = "my text"
for (comment in comments)
{
def text = comment.getBody()
if (text.contains(textToCheck) )
{
count++
}
}
return count ? count as Double : null
Now the problem is that I can't seem to use this in a JQL search,
Searcher and Template are set to Number but if I try to filter all issues with this field set to > 4 - it doesn't show correct results.
Any idea what am I doing wrong?
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @daniellec ,
hard to say right off the bat. You should try the JQL for one or two specific issues and determine when it is working and when it is not.
The code looks fine anyway.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@daniellec Could you try reindexing your jira instance and check again?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@daniellec Perfect!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @daniellec , Welcome to the community !
This is most probably doable with script runner with calculated fields.
You will be using the getComments method from the CommentManager to retrieve the comments of the issue.
Antoine
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.