Add Date to 'Last Comments' Field - script runner

Hi,

 

I would like to have a customer field that showed 'date of last comment'-'last comment' for example:

10/08 - this is the last comment

 

I'm using script runner and can get the last comment but how do you add the date of the last comment at the beginnning of the field?

 

Thanks

Kevin

 

Currnet script:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.component.ComponentAccessor
def commentManager = ComponentAccessor.getCommentManager()
def comment = commentManager.getLastComment (issue)
comment.body

2 answers

1 accepted

1 vote
Jenna Davis Community Champion Aug 15, 2017

Hello, 

You can do something similar to this:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.component.ComponentAccessor

def commentManager = ComponentAccessor.getCommentManager()
def comment = commentManager.getLastComment (issue)
def date = comment.getCreated()

return ((date as String) + " " + comment.body)

 You may want to mess with the formatting a bit to make it look exactly as you want, but that will make the date the comment was created appear in front of the comment's body. :)

Let me know if you have any problems or questions!

Regards, 

Jenna

Hi Jenna,

 

Thanks so much for the quick response. this works realy well!! :)

How do I play with the format? (sorry very new to all this)

Would like to just show 'Aug 11'

Many Thanks

Kevin 

Hi Jenna,

Found a solution, for the date format ;-)

Thanks some much for your help

Kevin

Hi Jenna, 

How do I get the last comment date of a public comment only?

Thank you. 

Where was this script added ? Is it in script runner

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.component.ComponentAccessor

def commentManager = ComponentAccessor.getCommentManager()
def comment = commentManager.getLastComment (issue)
def date = comment.getCreated()

return ((date as String) + " " + comment.body)

Yes the script was added to script runner.

It's added as a "scripted field".  Add a new custom field, select that type, and place it on the screens you want to see it on.

Then go to admin -> script runner -> scripted fields and add the script there.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jun 14, 2018 in Jira Service Desk

How the Telegram Integration for Jira helps Sergey's team take their support efficiency to the bank

...+ reading Fantasy). The same is true for him at the bank he works for: Efficiency is key when time literally equals money. Read on to learn how Sergey makes most of the time he has by...

503 views 3 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you