Import fields in eazyBI from Checklist for Jira app

If you use eazyBI for Jira Server and wish to import custom fields provided by Checklist for the Jira app, you could find this thread useful.

To import all items from the checklist field, you could use this code in your advanced settings:
(use Jira custom field ID instead of NNNNN in following codes)

#all items as comma separated string from Checklist
[jira.customfield_NNNNN]
data_type = "text"
name = "Checklist items all"

The next code would let you import a comma-separated list of only checked items from the field:

#only checked items from the custom field - comma saprated list
[jira.customfield_chlnames]
name = "Checked item list"
data_type = "text"
javascript_code = '''
if( issue.fields.customfield_NNNNN){
var result = 
  getDocument("/rest/api/latest/issue/" + issue.key +"?fields=customfield_NNNNN");
var resultArray = [];
    if (result){
        for(x of result.fields.customfield_NNNNN){
          if(x.checked)
            {
              resultArray.push(x.name)
            }
        }
    issue.fields.customfield_chlnames = resultArray.join(",");
      }
}
'''

The first two fields when imported as properties would let you see the details per issue level.

The last code would create an integer number that would count the checked items in your CHecklist field. This field can be imported as measure and used in report to count checked items in other hierarchy levels or even when “Issue” dimension won’t be used in the report.

#counts only checked items and imports as measure
[jira.customfield_chlcheckedcount]
name = "Checked item count"
data_type = "integer"
measure = true
javascript_code = '''
if( issue.fields.customfield_NNNNN){
var result = 
  getDocument("/rest/api/latest/issue/" + issue.key +"?fields=customfield_NNNNN");
var counter = 0;
    if (result){
        for(x of result.fields.customfield_NNNNN){
          if(x.checked)
            {
              counter++;
            }
        }
    if(counter>0) {issue.fields.customfield_chlcheckedcount = counter;}     
      }
}
'''

Martins / eazyBI:

4 Likes

You can add one more code to advanced settings to import count total items for a checklist field

[jira.customfield_chlallitc]
name = "chl all item count"
data_type = "integer"
measure = true
javascript_code = '''
if(issue.fields.customfield_18500){
var result = 
  getDocument("/rest/api/latest/issue/" + issue.key +"?fields=customfield_18500");
var itemcounter = 0;
    if (result){
        for(x of result.fields.customfield_18500){
          if(x.name)
            {
              itemcounter++;
            }
        }
    if(itemcounter>0) {issue.fields.customfield_chlallitc = itemcounter;}     
      }
}
'''

Just make sure you import the field as a measure from the import options page.

Later you can create a report with a calculated measure that has cell conditional formatting and show the percentage checked vs all.
Martins / eazyBI

2 Likes

Hi,
Is it possible to do it as a dimension with separate values?

If we have three values First, Second, Third
I select two values in the issue, First and Second,

As a dimension only one value is shown separated by commas (First, Second).

I need the dimension to show two values, First and Second.

Thank you.

@teomolina

Where do you see such a dimension with one value (by commas) in my screenshot?

There is a workaround to import the field as a multi-value dimension, but you should be careful with multi-value dimensions as issues can be double-counted.

What is the use-case? Why would need to separate values as unique dimension members? What do expect to calculate per each “True” value?

Martins / eazyBI

Three values in checklist:
A, B, C

I have three issues
Issue 1 → Selected A,B
Issue 2 → Selected B
issue 3 → Selected B, C

What is currently working with Dimension, to get the issues created:
A, B → 1 issue
B → 1 issue
B,C → 1 issue

What I would like too;
A → 1 issue
B → 3 issues
C → 1 issue

The total number of issues (4) does not match the actual issues (3) but that does not matter.

What code have you used in advanced settings to define this dimension?
My example above doesn’t share details on how to import the checklist field as dimension.

Martins

I used the same code, adding dimension = true.
And with that I have the first part:
A, B → 1 issue
B → 1 issue
B, C → 1 issue

I don’t know if there is any way to get also the second part.

You can import dimension with multiple_values = false condition, but it would require double import if the field is already imported without this setting.

Please provide exact code you used to define dimension and I will help you modify it to import each value as separate member.

Martins / eazyBI

Code I’m using

#DOR
[jira.customfield_10601]
name = "DOR"
data_type = 'string'
dimension = true

#only checked items from the custom field - comma saprated list
[jira.customfield_DORSelect]
name = "DOR Select"
data_type = "string"
dimension = true
multiple_values = false
javascript_code = '''
if (issue.fields.issuetype.name=="Story" || issue.fields.issuetype.name=="Bug" || issue.fields.issuetype.name=="Feature") {
var result = getDocument("/rest/api/latest/issue/" + issue.key +"?fields=customfield_10601");
var resultArray = [];
    if (result){
        for(x of result.fields.customfield_10601){
          if(x.checked)
            {
              resultArray.push(x.name)
            }
        }
    issue.fields.customfield_DORSelect = resultArray.join(",");
      }
}
'''

@teomolina

In this case, here is what you can try the following steps:

  1. open import options and unselect the field “DOR Select” and import data without it. Wait while import finishes. That will drop the field from the database with your current advanced settings

  2. make changes to advanced settings as follows;

#only checked items from the custom field - comma saprated list
[jira.customfield_DORSelect]
name = "DOR Select"
data_type = "string"
dimension = true
multiple_values = true
split_by = ","
javascript_code = '''
if (issue.fields.issuetype.name=="Story" || issue.fields.issuetype.name=="Bug" || issue.fields.issuetype.name=="Feature") {
var result = getDocument("/rest/api/latest/issue/" + issue.key +"?fields=customfield_10601");
var resultArray = [];
    if (result){
        for(x of result.fields.customfield_10601){
          if(x.checked)
            {
              resultArray.push(x.name)
            }
        }
    issue.fields.customfield_DORSelect = resultArray.join(",");
      }
}
'''
  1. open the import options page and import “DOR Select” field as dimension.

Martins / eazyBI

With this code an error is displayed.
image

I have tried and it is the following line:
multiple_values = true

If remove that line, there is no error, but the result does not change and still show the grouped values.

Try adding extra validation for the Js

#only checked items from the custom field - comma saprated list
[jira.customfield_DORSelect]
name = "DOR Select"
data_type = "string"
dimension = true
multiple_values = true
split_by = ","
javascript_code = '''
if (issue.fields.issuetype.name=="Story" || issue.fields.issuetype.name=="Bug" || issue.fields.issuetype.name=="Feature") {
var result = getDocument("/rest/api/latest/issue/" + issue.key +"?fields=customfield_10601");
var resultArray = [];
    if (result){
        for(x of result.fields.customfield_10601){
          if(x.checked)
            {
              resultArray.push(x.name)
            }
        }
    if(issue.fields.customfield_10601){issue.fields.customfield_DORSelect = resultArray.join(",");}
      }
}
'''
1 Like

Checklist addon allows users to insert heading among items. So it can be useful to filter these type of entries (via isHeader parameter). E.g.

[jira.customfield_chlallitc]
name = "chl all item count"
data_type = "integer"
measure = true
javascript_code = '''
var result = 
  getDocument("/rest/api/latest/issue/" + issue.key +"?fields=customfield_18500");
var itemcounter = 0;
    if (result){
        for(x of result.fields.customfield_18500){
          if(x.name && !x.isHeader)
            {
              itemcounter++;
            }
        }
    if(itemcounter>0) {issue.fields.customfield_chlallitc = itemcounter;}     
      }
'''
2 Likes

Hello! Im trying to add a checklist via the advanced Settings but I get this error :

Execution of custom JavaScript code raised the following error:
TypeError: Cannot read property “customfield_12001” from undefined

Here is the code :

#Acceptance Criteria
[jira.customfield_12001]
data_type = "text"
name = "Acceptance Criteria"

#only checked items from Acceptance criteria - comma saprated list
[jira.customfield_ACnames]
name = "Checked Acceptance Criteria"
data_type = "text"
javascript_code = '''
var result = 
  getDocument("/rest/api/latest/issue/" + issue.key +"?fields=customfield_12001");
var resultArray = [];
    if (result){
        for(x of result.fields.customfield_12001){
          if(x.checked)
          {
            resultArray.push(x.name)
          }
        }
        issue.fields.customfield_ACnames = resultArray.join(",");
     }
'''

Thank you :slight_smile:

1 Like

@Christopher_Gervais

You would need one extra validation for the field 12001 for issues when this field is not entered.

Try the following in your second script:

#only checked items from Acceptance criteria - comma saprated list
[jira.customfield_ACnames]
name = "Checked Acceptance Criteria"
data_type = "text"
javascript_code = '''
if(issue.fields.customfield_12001){
var result = 
  getDocument("/rest/api/latest/issue/" + issue.key +"?fields=customfield_12001");
var resultArray = [];
    if (result){
        for(x of result.fields.customfield_12001){
          if(x.checked)
          {
            resultArray.push(x.name)
          }
        }
        if(issue.fields.customfield_12001){issue.fields.customfield_ACnames = resultArray.join(",");}
     }
}
'''

Martins / eazyBI

Hello Martins,

I tried the script you sent me, but I still get the same error.
I also tried the “if(issue.fields.customfield_12001){}” condition within all the section under “if (result) {}” but still no success :-/

Thank you

@Christopher_Gervais

Make sure that the custom field 12001 is also selected and imported as property.

Martins

Hello Martins,

I have checked and import as property as follow :

Am I missing something?

Thank you :slight_smile:

@Christopher_Gervais

Do you see any values for issues when selecting the property “Issue Acceptance Criteria” from Measures dimension in columns, and “Issue” dimension members (at issue-level) in report rows?
Is Acceptance criteria field correctly imported?

Martins / eazyBI

Hello Martins,

I can confirm that some have a value (Issue with values in the Checklist), and other are empty (without value in the checklist)

Thank you :slight_smile: