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.CommentManagerimport java.util.GregorianCalendarimport java.util.Dateimport java.util.Calendardef comments = CommentManager.getComments(issue)def count = 0def 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
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
Thank you!
Wow thank you so much Ben, will try and update!
@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.CommentManagerimport com.atlassian.jira.component.ComponentAccessorList<String> list = new ArrayList<String>();def comments = ComponentAccessor.commentManager.getComments(issue)def count = 0def 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?
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.
It looks like you're new here. Sign in or register to get started.