Adaptavist Script Listiner Jira Cloud Extract Text From The Last Comment

Created by Kristian Walker last modified
* This example script listner script must bve configured to fire on the 'Issue Updated' Event and shows how to get all comments on the issue and then to get the last comment and to save the text from it to a varible. 
* "All right, title and interest in this code snippet shall remain the exclusive intellectual property of Adaptavist Group Ltd and its affiliates. Customers with a valid ScriptRunner
* license shall be granted a  non-exclusive, non-transferable, freely revocable right to use this code snippet only within their own instance of Atlassian products. This licensing notice cannot be removed or
* amended and must be included in any circumstances where the code snippet is shared by You or a third party." 

// Get the key of the current issue
def issueKey = issue.key

// Make a call to the Get Comments API to get all the comments on the issue
def getComments = get("/rest/api/3/issue/${issueKey}/comment")
        .header('Content-Type', 'application/json')

// If the issue has comments        
if( != 0){
// Save the last comment to a variable called lastComment
def lastComment = getComments.body.comments.last().body.content.content.text.toString().replaceAll("\\[", "").replaceAll("\\]", "")

// log out the last comment"The Last Comment = " + lastComment)
// If the issue has no comments log out  message to say this."The issue has no comments")

Comments (0)


You can clone a snippet to your computer for local editing. Learn more.