Calculating the number of comments - by specific USER

There is a similar post referencing adding JavaScript to EazyBI’s advanced settings to get the actual COMMENT data out of JIRA:

https://community.eazybi.com/t/calculating-the-number-of-comments/255

This solution works great.

However would like to know if a similar solution would work to get the comments made by a specific Assignee and / or Reporter.

I have Rows with a list of all existing projects, and would like to have a column with a user-defined, [Measure] > “Calculated member” that is able to show all the projects that “User X” has commented on.

Thank you in advance for your feedback.

Hi @chrischarles2002,

In the mentioned community post Calculating the number of comments , is an example of how to import comment count using JavaScript calculated custom fields.

To count comments by each author, you may modify JavaScript code. To do this, declare that each issue might have a set (array) of user names who have commented on it and comment count accordingly. To represent names of comment authors in eazyBI, you may use some existing dimension which contains user names, like, Assignee dimension.

Code for advanceds settings with JavaScript calcaulted custom field might look like this:

#Comments by user - Assignee
[jira.customfield_comments_byuser]
name = "Comments by user"
data_type = "integer"
measure = true
multiple_dimensions = ["Time","Assignee"]
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];
      commenta.push(comment.created.toString().substr(0,10) + "," + comment.author.name + ",1");
  }
  issue.fields.customfield_comments_byuser = commenta.join("\n");
}
'''

In a report, use Assignee dimension to represent comment count by authors.

Best,
Zane / support@eazyBI.com

1 Like

@zane.baranovska I’m having issues when trying to use the JS calculated custom field code from the 2017 post.

[jira.customfield_comments]
name = "Comments"
data_type = "integer"
measure = true
javascript_code = '''
if (issue.fields.comment && issue.fields.comment.comments ) {
	issue.fields.customfield_comments = issue.fields.comment.comments.length;
}
'''

When trying this code with the “Test custom JavaScript code with the issue” option, I get the following error back: Execution of custom JavaScript code raised the following error:
unterminated string literal

Any idea what needs to change to make it work?

@colinf

In eazyBI are several places where you can paste in the JavaScript code.

  1. When defining the new custom field, then you should paste the custom field definition with JavaScript code to get data for that custom field in eazyBI advanced settings (eazyBI >> Settings >> tab Advanced settings). This section is available to eazyBI administrators and Jira administrators.
    https://docs.eazybi.com/eazybijira/data-import/custom-fields/advanced-settings-for-custom-fields

  2. You may modify received data during data import with JavaScript code placed in eazyBI import options (eazyBI >> Source Data >> Additional options >> field Custom JavaScript code). This option usually is used to mas some sensitive data or remove them at all.
    https://docs.eazybi.com/eazybijira/data-import/advanced-data-import-options/custom-javascript-code

  3. You may test JavaScript code part on a particular issue while defining a new JavaScript calculated custom field in eazyBI import options (eazyBI >> Sourece Data >> Additional options >> field Custom JavaScript code). Yes, it is the same field as in point 2 for modifying data. When testing JavaScript code, use only the javascript_code part that is between opening and closing quotes '''. And when testing is done, the code should be cleared from the area and not saved.
    https://docs.eazybi.com/eazybijira/data-import/custom-fields/javascript-calculated-custom-fields#JavaScriptcalculatedcustomfields-ValidatetheJavascriptcodebeforeusingitinthecustomfielddefinition

The given code for “Comments” is a complete code for eazyBI advanced settings. If you want to test it beforehand, you might want to use only the JavaScript part between quotes ''' (see point 3).

Best,
Zane / support@eazyBI.com

For eazyBI customers who use eazyBI for Jira Cloud, a slightly different Javascript should be used to correctly map assignee names to “Assignee” dimension.

[jira.customfield_comments_byuser]
name = "Comments by user"
data_type = "integer"
measure = true
multiple_dimensions = ["Time","Assignee"]
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];

      if(comment.author)
      {
      commenta.push(comment.created.toString().substr(0,10) + "," + comment.author.accountId + ",1");
  		}
  		else
  		commenta.push(comment.created.toString().substr(0,10) + "," + "(unassigned)" + ",1");	
  	}
  issue.fields.customfield_comments_byuser = commenta.join("\n");
}
'''

Martins / eazyBI support

I may need user name instead of account ID, how can I achieve it?

@Ramesh_Mashetty1
If you use the new calculated field (mapped to “Time” and “Assignee” dimension) imported as a measure with the “Assignee” dimension, you would see Assignee display names.
Or please share more details on where do you get the account ID exactly.

Martins / eazyBI


under issue comments by user, it is showing date & account ID & however I need user display name
@martins.vanags

@Ramesh_Mashetty1

“Comments by user” is impored also as measure and mapped to “Assignee” and “Time” dimension.
If you won’t use accountID you won’t be able to analyze the count of comments by users.
Perhaps, you could drag “Assignee” dimension in rows and see comments split by assignees.

Or, you could create another calculated field “Comments by user name” from advanced settings and import it in the cube, where you could use the slightly different syntax in the Javascript where you use comment.author.displayName item from the JSON structure instead of accountID.

Martins/ eazyBI

@martins.vanags I’ve tried the second option but no luck same output as for account ID
when trying first option it is throwing error as timeout error: 60 second please try making query simpler

Please share the full code you tried to define new calculated field for author Name.

Martins

@martins.vanags
[jira.customfield_comments_byuser]
name = “Comments by user”
data_type = “integer”
measure = true
multiple_dimensions = [“Time”,“Assignee”]
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];
if(comment.author)
{
commenta.push(comment.created.toString().substr(0,10) + “,” + comment.author.displayName + “,1”);
}
else
commenta.push(comment.created.toString().substr(0,10) + “,” + “(unassigned)” + “,1”);
}
issue.fields.customfield_comments_byuser = commenta.join("\n");
}
‘’’

Here I’ve used dispalyName instead of account ID

It won’t be possible to map displayName to “Assignee” dimension, therefore, you could possibly import the new field only as property for “Issue” dimension members.

First, unimport the second field and import this field only:

[jira.customfield_comments_byusn]
name = "Comments by userName"
data_type = "string"
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];

      if(comment.author)
      {
      commenta.push(comment.created.toString().substr(0,10) + "," + comment.author.displayName + ",1");
      }
      else
      commenta.push(comment.created.toString().substr(0,10) + "," + "(unassigned)" + ",1"); 
    }
  issue.fields.customfield_comments_byusn = commenta.join("\n");
}
'''

Martins / eazyBI

1 Like

This is a very similar script but it would count comments made just by the assignee of the issue:

#Comments by user - Assignee
[jira.customfield_as_comm]
name = "Comments by assignee"
data_type = "integer"
measure = true
multiple_dimensions = ["Time","Assignee"]
javascript_code = '''
var commenta = new Array();
var allcomments = issue.fields.comment;
if (allcomments && allcomments.comments && issue.fields.assignee) {
  var comments = issue.fields.comment.comments;
  for (var i = 0; i < comments.length; i++) {
      var comment = comments[i];
    
    if(comment.author && comment.author.key == issue.fields.assignee.key)
    {
      commenta.push(comment.created.toString().substr(0,10) + "," + comment.author.name + ",1");
    }
  }
  issue.fields.customfield_as_comm = commenta.join("\n");
}
'''