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
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Atlassian Community Events