Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Trying to copy the last EXTERNAL comment to a custom field

We're using this script to set up a custom field called Last comment (script field):

* Field name: Last Comment
* Template: Text Field (multi-line)
* Description:
* Returns the last comment on an issue.

import com.atlassian.jira.component.ComponentAccessor

// get the latest comment
def commentManager = ComponentAccessor.getCommentManager()
def comment = commentManager.getLastComment(issue)

// check to see if comments exist - return comment body if so
if (comment != null) {
return comment.body

return null

This returns the last comment, whether it's internal or external. 

We need this script to return ONLY the last EXTERNAL comment.

I found this link;

But we get an error:

groovy.lang.MissingPropertyException: No such property: transientVars for class: Script8473 at

How can we set transientVars as a script field?

1 answer

1 accepted

2 votes
Answer accepted

Hi @Samuel Carter

For your requirement, it would be best to use the ScriptRunner Listener with the Issue Commented event.

Below is a working sample code for your reference:-

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.Comment
import groovy.json.JsonSlurper

final SD_PUBLIC_COMMENT = 'sd.public.comment'

def issue = event.issue as MutableIssue
def issueEvent = event as IssueEvent
def user = issueEvent.user
def comment = issueEvent.comment

def customFieldManager = ComponentAccessor.customFieldManager
def issueManager = ComponentAccessor.issueManager
def commentPropertyService = ComponentAccessor.getComponent(CommentPropertyService)

def sampleMultiLine = customFieldManager.getCustomFieldObjectsByName('Sample Multi Line Text').first()

def isInternal = { Comment c ->
def commentProperty = commentPropertyService.getProperty(user,, SD_PUBLIC_COMMENT).entityProperty.orNull

if (commentProperty) {
def props = new JsonSlurper().parseText(commentProperty.value) as Map
else {

if (comment && !isInternal(comment)) {
issue.setCustomFieldValue(sampleMultiLine, comment.body)
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
return false

Please note that the sample code provided is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a screenshot of the Listener Configuration for your reference:-


Below are a few test screenshots for your reference:-

1. When I first add a new public comment, the comment is copied to the text field as shown below:-


2. If I try to include a private comment, the text field is not updated as expected


3. If I add a new public comment, the text field is updated as expected.


I hope this helps to answer your question. :)

Thank you and Kind Regards,


Hi Ram,

I've implemented this code as a listener and it seems to do exactly as we require.


Thanks so much for your help!

Kind regards,


Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira Service Management

An unofficial way to monitor a JSM mail handler for errors

...eturns true if any content is returned for the s...

688 views 2 20
Read article

Atlassian Community Events