Count issues based on labels hierarchy number

I’ve a case where, in a project there are

  1. some issues with label 1
  2. some issues with label 1 & label 2
  3. some issues with label 1, label 2 & label 3
    My requirement is,
    any issue that has
  4. only label 1 and not label 2 & label 3 should count under scenario 1
  5. label 1 & label 2 and not label 3 should count under scenario 2 (#1 shouldn’t be counted here)
  6. label 1, label 2 & label 3 should count under scenario 3. (#1 & #2 shouldn’t be counted here)

For this, Getting a count of a specific issue type that has a combination of labels,

I modified code from the above link as below:
[jira.customfield_sc]
name = “Scenario”
data_type = “string”
dimension = true
javascript_code = ‘’’

var label1 = "fail_rev_1";
var label2 = "fail_rev_2";
var label3 = "fail_rev_3";
var label = issue.fields.labels;

if(label){
  if (label.indexOf(label1) != -1 && 
     label.indexOf(label2) = -1 &&
     label.indexOf(label3 = -1))
    {     
      issue.fields.customfield_sc = "Scenario1";
    }
  if (label.indexOf(label1) != -1 && 
     label.indexOf(label2) != -1 &&
     label.indexOf(label3) = -1)
    {     
      issue.fields.customfield_sc = "Scenario2";
    }
  if (label.indexOf(label1) != -1 && 
     label.indexOf(label2) != -1 &&
     label.indexOf(label3) != -1)
    {     
      issue.fields.customfield_sc = "Scenario3";
    }
};
''' 

After saving the above code in settings, and selecting the scenario custom field in import options and attempting to import,
I get this error: Execution of custom JavaScript code raised the following error:
Invalid assignment left-hand side.

Hi,

It seems your code has an import error due to Javascript mistake.
Try using two equals (==) for filter validation in the code where you search for labels that match the filter condition.

[jira.customfield_sc]
name = "Scenario"
data_type = "string"
dimension = true
javascript_code = '''

var label1 = "fail_rev_1";
var label2 = "fail_rev_2";
var label3 = "fail_rev_3";
var label = issue.fields.labels;

if(label){
  if (label.indexOf(label1) != -1 && 
     label.indexOf(label2) == -1 &&
     label.indexOf(label3 == -1))
    {     
      issue.fields.customfield_sc = "Scenario1";
    }
  if (label.indexOf(label1) != -1 && 
     label.indexOf(label2) != -1 &&
     label.indexOf(label3) == -1)
    {     
      issue.fields.customfield_sc = "Scenario2";
    }
  if (label.indexOf(label1) != -1 && 
     label.indexOf(label2) != -1 &&
     label.indexOf(label3) != -1)
    {     
      issue.fields.customfield_sc = "Scenario3";
    }
};
''' 

Martins / eazyBI team

1 Like

Thank you. It works now.