Pull in all comments for an issue

I have found sample code for pulling in comment timestamps as well as authors.

Does anyone have any sample code for pulling in all comments related to an issue so they can be displayed on the screen?

I am using the latest comment field which is added as a custom field to the overall Settings for Last Comment Date and Last Comment Text.

Thanks in advance,
Dennis

For anyone else looking to do this here is one option:

[jira.customfield_all_comments]
name = "All Comments"
data_type = "text"
javascript_code = '''
var commenta = new Array();
var allcomments = issue.fields.comment;
if (allcomments && allcomments.comments ) {
  var comments = issue.fields.comment.comments;
  for (var i = 0; i < comments.length; i++) {
    var comment = comments[i];
	  var commentdate = comment.created.toString().substr(0,19);
      commenta.push( commentdate + ', ' + comment.author.accountId + ', ' + comment.author.displayName + ', ' + comment.body );
      }
  issue.fields.customfield_all_comments = commenta.join("\n");
}
'''

This will provide the date / time stamp - author account id - author display name - comment body all on individual lines within the report.

The will show as oldest first and newest on the bottom.

2 Likes

Hi @DennisT

It is great that you already found the answer to your own question and shared it with others.
Sharing is the real deal in communities!

Btw, that is the right way to import all comments in a property for each issue dimension member (by using a calculated field with Javascript in advanced settings)

Well done!
Martins / eazyBI support

Hello @martins.vanags

This is very close to what I’m trying to accomplish, however I would need each comment to be in the same row according to the date they were posted instead all in the same row, please see the images bellow. Essentially I’d like to separate the comments by date.


@nolivaiko

eazyBI does not support importing a separate “Comment” dimension as you might expect.
If you need to count comments by days, you could try a different Javascript for field definition.
That would let you see the count of comments per day.

Martins / eazyBI

Hi @martins.vanags

I was able to pull the comments of assignees and reporters but instead if I want of pull the last comment of a particular issue irrespective of reporter or assignees.
How to pull that.

Hi,

I built this in the Advanced settings for eazyBI so they data is there as a measure when we want to display just the last comment information.

Split into three measures so we have the comment text, comment date, and comment author

Code I used is as follows:

# Pulls the last comment made on an issue
[jira.customfield_lastcommentt]
name = "Last comment text"
data_type = "text"
javascript_code = '''
if (issue.fields.comment && issue.fields.comment.comments && issue.fields.comment.comments.length > 0)  {
  var lastcomment = issue.fields.comment.comments[issue.fields.comment.comments.length-1];
  issue.fields.customfield_lastcommentt = lastcomment.body;
}
'''

# Pulls the last comment date from an issue
[jira.customfield_lastcommentdate]
name = "Latest comment date"
data_type = "datetime"
json_fields = ["comment"]
javascript_code = '''
var comments = issue.fields.comment.comments;
if (comments.length > 0) {
  var comment = comments[comments.length - 1];
  issue.fields.customfield_lastcommentdate = comment.created;
}
'''

# Pulls the last comment author from an issue
[jira.customfield_lastcommentauthor]
name = "Latest comment author"
data_type = "text"
json_fields = ["comment"]
javascript_code = '''
var comments = issue.fields.comment.comments;
if (comments.length > 0) {
  var comment = comments[comments.length - 1];
  issue.fields.customfield_lastcommentauthor = comment.author;
}
'''

Hi @DennisT

But please find the below screenshot its showing:

Hi,

My guess would be the quotes getting modified when posting here.

I would copy the code from here then paste into notepad or something to get the double quotes and single quotes formatted properly.

@DennisT
Your guess makes sense.
These are not correct quotes for definition in advanced settings.
See syntax examples here: JavaScript calculated custom fields

Martins / eazyBI

Hi @DennisT

Thank you that worked perfectly