Hi,
I have a project with about 2 dozen custom fields that have a string values such as:
Pass
Fail - reason 1
Fail - reason 2
Fail - reason 3
I need to calculate the total percentage of passes on every issue within this project. The variations of fail do not matter I just need to calculate the total number of passes received against the total number of fields.
I am very new to the reporting/admin side of JIRA and have found how to do things similar when dealing with custom fields that have numeric values, but I have picklist string values that must be used for this project.
Can someone point me in the right direction?
so here is the script I created to solve this, is probably isn't the most elegant but our JIRA instance is an oddball.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import java.text.NumberFormat
CustomFieldManager cfm = ComponentAccessor.getCustomFieldManager();
String att1 = "Field name1"; //call all your fields here
ArrayList list = new ArrayList();
list.add(att1); //add all fields to a list
Double passCount = 0;
int maxAttCount = 0;
if (list.isEmpty()) {
maxAttCount = 0;
}
else {
maxAttCount = list.size();
}
for (int i=0; i < maxAttCount; i++) {
String customField = list.get(i).toString();
if (customField != null){
CustomField cf = cfm.getCustomFieldObjectByName(customField);
Map cfVal = issue.getCustomFieldValue(cf) as Map;
if (cfVal){
String firstValue = cfVal.get(null);
if (firstValue.toString().equals("Pass")) { //this is the field attribute that will be calculated
passCount = passCount + 1;
}
else if (firstValue.toString().equals("Fail")) {
}
else if (firstValue.toString().equals("FYI")) {
}
else if (firstValue.toString().equals("NA")) {
}
}
}
}
int finalCount = passCount/15*100;
return finalCount + "%";
else if (firstValue.toString().equals("FYI")) {
}
else if (firstValue.toString().equals("NA")) {
}
}
}
}
int finalCount = passCount/15*100; //only 15 of the fields actually contain a fail attribute
return finalCount + "%"
Hi Joe- you're likely going to need a scripting app to help perform mathematical operations to aggregate statistical information about a project, particularly when you're running metrics on options within a multi-option custom field.
Here's a quick example of a SIL script that you can run whenever an issue is created or edited in your project via SIL Listeners or on a set schedule with SIL Scheduler. This is made possible with Power Scripts for Jira.
string jql=
"project=PROJ"
; //update with your project key
string [] allProjectIssues=selectIssues(jql);
number totalProjectIssues=0;
number totalPasses=0;
for(string issue in allProjectIssues) {
totalProjectIssues += 1;
if(%issue%.customfield_12345=="Pass") {
totalPasses += 1;
}
}
number percentPass = (totalPasses / totalProjectIssues) * 100;
customfield_23456 = percentPass; // assumes you want to store this value in a number custom field
Hope this helps!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.