Forums

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

Using JMCF to create a scripted custom field to represent last comment, but can't get comment array.

Andrea Hakim January 22, 2025

In Jira Cloud, have the JMCF app by AppFire and trying to create a scripted field to display the last comment body, date and author.  When I test, I recieve this error:  

 

TypeError: Cannot read property 'comments' of undefined
 in script at line 2, column 37

 

// Get the comments from the issue

var comments = issue.fields.comment.comments;

if (comments && comments.length > 0) {

    // Get the last comment

    var lastComment = comments[comments.length - 1];

    // Extract the details

    var lastCommentBody = lastComment.body;

    var lastCommentDate = lastComment.created;

    var lastCommentAuthor = lastComment.author.displayName;

    // Format the output

    var result = "Last Comment: " + lastCommentBody + "\n" +

                 "Last Comment Date: " + lastCommentDate + "\n" +

                 "Last Comment Author: " + lastCommentAuthor;

    // Return the result

    return result;

} else {

    return "No comments available.";

}

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events