the below script works and retrun the perfect values in the console log when i test it for an issue using the "test" button but when i run the scrpit aka "recalculate" for all issues on the instance it returns "WHY" for all issues. I have checaked that all issues have the likelihood and consequenceque fields filled out, both field are single select so dont execpt unclean data. I am not able to access logs when i run the batch aka "recalculate". Im at a loss for next steps.
I have used this before on jira server and i was also able to embed css to change the background colour of the rating field depending on the rating, but for now i'd be happy if it just auto calculates correctly.
TIA
SCRIPT
var likelihood = issue.fields['customfield_101xx']; // Replace with the actual field ID for Likelihood
var consequence = issue.fields['customfield_101yy']; // Replace with the actual field ID for Consequence
console.log("Likelihood Value: " + likelihood);
console.log("Consequence Value: " + consequence);
// Check if either field is missing and return "Unknown"
//if (!likelihood || !consequence) {
// return "Likelihood or Consequence field is missing for issue " + issue.key + ".";
//}
// Log the values for debugging (optional, in a real scenario you may not use `console.log` in production)
// Access the 'value' property of the field options (since fields store option objects)
var likelihoodValue = likelihood ? String(likelihood.value) : null; // Convert to string
var consequenceValue = consequence ? String(consequence.value) : null; // Convert to string
console.log("Processing issue: " + issue.key);
console.log("Likelihood Value: " + likelihoodValue);
console.log("Consequence Value: " + consequenceValue);
// Initialize risk category
var riskCategory = "WHY";
// Use if-else to determine the risk category based on string comparison
if (likelihoodValue == "Almost Certain (Frequent)" && consequenceValue == "Extreme") {
riskCategory = "Extreme";
console.log("1");
} else if (likelihoodValue == "Almost Certain (Frequent)" && consequenceValue == "Major") {
riskCategory = "High";
console.log("2");
} else if (likelihoodValue == "Almost Certain (Frequent)" && consequenceValue == "Moderate") {
riskCategory = "Medium";
console.log("3");
} else if (likelihoodValue == "Almost Certain (Frequent)" && consequenceValue == "Minor") {
riskCategory = "Medium";
console.log("4");
} else if (likelihoodValue == "Almost Certain (Frequent)" && consequenceValue == "Insignificant") {
riskCategory = "Low";
console.log("5");
} else if (likelihoodValue == "Likely (Probable)" && consequenceValue == "Extreme") {
riskCategory = "Extreme";
console.log("6");
} else if (likelihoodValue == "Likely (Probable)" && consequenceValue == "Major") {
riskCategory = "High";
} else if (likelihoodValue == "Likely (Probable)" && consequenceValue == "Moderate") {
riskCategory = "Medium";
} else if (likelihoodValue == "Likely (Probable)" && consequenceValue == "Minor") {
riskCategory = "Low";
} else if (likelihoodValue == "Likely (Probable)" && consequenceValue == "Insignificant") {
riskCategory = "Low";
} else if (likelihoodValue == "Possible (Occasional)" && consequenceValue == "Extreme") {
riskCategory = "High";
} else if (likelihoodValue == "Possible (Occasional)" && consequenceValue == "Major") {
riskCategory = "Medium";
} else if (likelihoodValue == "Possible (Occasional)" && consequenceValue == "Moderate") {
riskCategory = "Medium";
} else if (likelihoodValue == "Possible (Occasional)" && consequenceValue == "Minor") {
riskCategory = "Low";
} else if (likelihoodValue == "Possible (Occasional)" && consequenceValue == "Insignificant") {
riskCategory = "Low";
} else if (likelihoodValue == "Unlikely (Uncommon)" && consequenceValue == "Extreme") {
riskCategory = "High";
} else if (likelihoodValue == "Unlikely (Uncommon)" && consequenceValue == "Major") {
riskCategory = "Medium";
} else if (likelihoodValue == "Unlikely (Uncommon)" && consequenceValue == "Moderate") {
riskCategory = "Medium";
} else if (likelihoodValue == "Unlikely (Uncommon)" && consequenceValue == "Minor") {
riskCategory = "Low";
} else if (likelihoodValue == "Unlikely (Uncommon)" && consequenceValue == "Insignificant") {
riskCategory = "Low";
} else if (likelihoodValue == "Rare (Remote)" && consequenceValue == "Extreme") {
riskCategory = "High";
} else if (likelihoodValue == "Rare (Remote)" && consequenceValue == "Major") {
riskCategory = "Medium";
} else if (likelihoodValue == "Rare (Remote)" && consequenceValue == "Moderate") {
riskCategory = "Low";
} else if (likelihoodValue == "Rare (Remote)" && consequenceValue == "Minor") {
riskCategory = "Low";
} else if (likelihoodValue == "Rare (Remote)" && consequenceValue == "Insignificant") {
riskCategory = "Low";
}
// Log the final calculated risk category
console.log("Calculated Risk Category for issue " + issue.key + ": " + riskCategory);
// Return the final risk category as a string
return riskCategory;
Just out of curiosity, are you using ScriptRunner for Jira Cloud in your instance as well?
If yes, then it would be possible to use ScriptRunner's Scripted field also.
Thank you and Kind regards,
Ram
Hi @Manali Butey -- Welcome to the Atlassian Community!
As Jira Misc Custom Fields (JMCF) is a third-party addon / app, I recommend contacting the vendor through the marketplace for support on this question:
https://marketplace.atlassian.com/apps/27136/jira-misc-custom-fields-jmcf?tab=overview&hosting=cloud
Kind regards,
Bill
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.