It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

(Scriptrunner) Get last comment for link in Web UI

page link

In the last field on this screenshot, you can see ${issue.summary}, and I have been able to do things like ${issue.description} but I am looking to get the last comment made. Is this possible, or is there a list of all fields accessible this way?


Alternatively, when an agent is making a comment in service desk, is there a way to automatically append a link at the end of the comment? Is this possible with either built in workflows, Automation for Jira, or ScriptRunner?

2 answers

1 accepted

0 votes
Answer accepted

Hi @Jordan_Berry 

Here is what you can do.

First create a REST Endpoint with ScriptRunner. 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.sal.api.ApplicationProperties
import com.atlassian.sal.api.UrlMode
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import groovy.transform.BaseScript
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.user.ApplicationUser

@BaseScript CustomEndpointDelegate delegate

def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.jiraAuthenticationContext?.loggedInUser

searchGoogle(httpMethod: "GET") { MultivaluedMap queryParams ->

def issueId = queryParams.getFirst("issueId") as Long
def issue = issueManager.getIssueObject(issueId)

CommentManager commentMgr = ComponentAccessor.getCommentManager()
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().loggedInUser

def lastComment = commentMgr.getComments(issue)?commentMgr.getComments(issue).last().body: ""
def encodedComment =, "UTF-8")


 Then in your Custom web item use the following in the Link field.


The purpose of the custom REST end point is to do further processing like fetching the last comment and then when you call the rest url with the issue id as a parameter then the last comment is fetched, encoded and redirected to Google. 

I hope it was helpful. Let me know.


This worked like a charm. Thank you!

Like Ravi_Sagar__Adaptavist_ likes this

Hi @Jordan_Berry 

Those properties that can be accessed via issue.* are the issue fields. However comment is not an issue field. As you know, there might be multiple comments and you can't access the latest one without code or a third party app which gives you the last comment as a custom field.

You can write your own Last comment scripted custom field via Script runner, or you can use one of the comment custom field apps in Atlassian marketplace.

Since I am one of the folks behind Snapbytes, I can recommend Enhancer Plugin's Comment custom field so that you can define Last Comment custom field easily, then use it in script runner as $issue.getCustomFieldValue($customFieldManager.getCustomFieldObject("...."))

But, I don't think it is a good idea to use comment content in url because comment might contain illegal characters which should be Url encoded first. Also it can be too long for the Url that might be truncated in some systems.

I hope I was clear


Hey Tuncay,

While I appreciate the answer, I feel this should be possible with the add-ons that we have already purchased

Great :)

Suggest an answer

Log in or Sign up to answer

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you