Hi everyone,
The situation is this:
I have 4 custom fields which contain values (Complete, Incomplete, Partial).
I need a 5th field, the result field, which will give me a score (Poor, Average, Good, Very Good, Excellent) based on the average of points calculated from the first 4 fields.
I have assigned points as follows:
- Incomplete: 0 pts
- Partial: 50 pts
- Complete: 100 pts
For the result field, I am using a Scripted Field.
Just to be clear, it looks like this when you create a new field.
scriptedfield.png
This is what I've written up so far:
// We declare our variables and pull the data from the ticket
def stringContent = issue.get("customfield_19687");
def stringCategory = issue.get("customfield_19688");
def stringSolution = issue.get("customfield_19689");
def stringClarity = issue.get("customfield_19690");
def scoreContent;
def scoreCategory;
def scoreSolution;
def scoreClarity;
def scoreTotal;
// Storing the score from each drop down into a numeric variable
if (stringContent == "Incomplete") {
scoreContent = 0;
} else if (stringContent == "Complete") {
scoreContent = 100;
} else {
scoreContent = 50;
}
if (stringCategory == "Incomplete") {
scoreCategory = 0;
} else if (stringCategory == "Complete") {
scoreCategory = 100;
} else {
scoreCategory = 50;
}
if (stringSolution == "Incomplete") {
scoreSolution = 0;
} else if (stringSolution == "Complete") {
scoreSolution = 100;
} else {
scoreSolution = 50;
}
if (stringClarity == "Incomplete") {
scoreClarity = 0;
} else if (stringClarity == "Complete") {
scoreClarity = 100;
} else {
scoreClarity = 50;
}
// We refresh our total score variable
scoreTotal = (scoreContent + scoreCategory + scoreSolution + scoreClarity) / 4;
// We set our field value depending on the total score
if (scoreTotal <= 50) {
return "Poor";
} else if (scoreTotal < 75) {
return "Average";
} else if (scoreTotal < 84) {
return "Good";
} else if (scoreTotal < 90) {
return "Very good";
} else {
return "Excellent";
}
Currently, the field does not show because it has no results.
I already tested the calculations and everything by replacing the first part and assigning values to the variables directly in the code
def stringContent = "Complete";
def stringCategory = "Complete";
def stringSolution = "Incomplete";
def stringClarity = "Patrial";
and it seems to work fine.
Which leads me to believe this part is the culprit:
def stringContent = issue.get("customfield_19687");
def stringCategory = issue.get("customfield_19688");
def stringSolution = issue.get("customfield_19689");
def stringClarity = issue.get("customfield_19690");
Am I even doing the right thing here? How do I get the values from my custom fields?
Thanks!