Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

ScripRunner - Script Fields Last Comment Date By Agent And Customer

David Harkins
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 27, 2021

Has anyone done or know how to script two fields, showing the date of the last comment on an issue by a Service Desk agent and a Service Desk Customer.

So two separate fields with two dates, giving an indication of who was the last to comment and how long ago.  i.e. is this something the we should be chasing up with the customer or have we let an issue slip behind.

3 answers

1 accepted

1 vote
Answer accepted
David Harkins
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 28, 2021

And a working version :-) 

import com.atlassian.jira.component.ComponentAccessor

def commentManager = ComponentAccessor.commentManager
def comments = commentManager.getComments(issue)
def groupManager = ComponentAccessor.getGroupManager()

def sortedComments = comments.toSorted {a, b -> b.created <=> a.created }

for (comment in sortedComments) {
if (groupManager.getGroupNamesForUser(comment.authorApplicationUser).contains("jira-servicedesk-users")) {
return comment.created
break
}
}
return null
David Harkins
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 29, 2021

I changed the IF statement to a NOT to get last customer comment

0 votes
Gökçe Gürsel {Appfire}
Atlassian Partner
April 28, 2021

Hi @David Harkins ,

As an alternative, you can use Enhancer Plugin for Jira for this.

It has a dedicated field called Last comment Date & Last commented User and Last comment. These fields are also searchable.

jep-customfields-comment.pngimage2017-8-24+13-29-16.png

Please let me know if you have further questions.

Cheers,

Gökçe

Please note that I'm a member of the Snapbytes team who developed the Enhancer Plugin for Jira.

David Harkins
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 28, 2021

@Gökçe Gürsel {Appfire} 

The plugin may provide the required function, but also has a lot more features, so is probably overkill for what I need at this stage. But thank you for your suggestion.

0 votes
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 27, 2021

https://library.adaptavist.com/entity/show-last-comment-for-an-issue shows you how to get to a comment object, which you can ask for the created or updated dates, as well as the name of the author.

Note that "how long ago" is not scriptable - it's a moving target, so you'd have to be re-indexing constantly.

David Harkins
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 28, 2021

The how long would not be scripted in the field, but will enable queues to display issues that have not been commented on x days.

So we can get the name of the last comment author, if we need to get the last comment date by customer and the last comment date by agent, we would need to loop through all previous comments until a user match is made.

David Harkins
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 28, 2021

My progress so far:

import com.atlassian.jira.component.ComponentAccessor

def commentManager = ComponentAccessor.commentManager
def comments = commentManager.getComments(issue)

log.info("Comments:" + comments.size)

if (comments) {
comments.each { comment ->
log.info("Author" + comment.authorApplicationUser)
}
}
David Harkins
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 28, 2021

The Following:

import com.atlassian.jira.component.ComponentAccessor

def commentManager = ComponentAccessor.commentManager
def comments = commentManager.getComments(issue)
def groupManager = ComponentAccessor.getGroupManager()
//def ReturnDate = date
int check = 0

//log.info("Comments:" + comments.size)

for (comment in comments) {
log.info("Author" + comment.authorApplicationUser)
if (groupManager.getGroupNamesForUser(comment.authorApplicationUser).contains("jira-servicedesk-users")) {
log.info("Author is A Service Desk Agent")
return comment.created
break
}

}
return null

is returning the first comment where the user is a service desk agent :-( 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events