I added a new field and updated the code but it breaks the code on all the old tickets, how do I fix this? The above script does not work.
Do all five of your variables you are calculating from always have a value?
You'll need to cope with the absence of the data in the script, so the script knows to not try to do anything with it.
Imagine you're trying to add 3 fields in the new script. Instead of
total += fieldValue3
use
if (fieldValue3) { total += fieldValue3 }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm not sure I'm following how to go about that. I have tried to different ways of going about it:
def total = ((bvInt + tcInt + rrInt + svInt) / sizeInt) * 100;
def totalNull = ((bvInt + tcInt + rrInt) / sizeInt) * 100;
def result;
if(svInt==1 || 5 || 8 || 13){
return total
}else {
return totalNull
}
OR
def total = ((bvInt + tcInt + rrInt + svInt) / sizeInt) * 100
def totalNull = ((bvInt + tcInt + rrInt) / sizeInt) * 100
def result
if(svInt!=null){
return total
} else {
return totalNull
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You need to check if a field value is valid before you try to use it in a calculation.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.ComponentAccessor
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField bvField = customFieldManager.getCustomFieldObject("customfield_17937")
CustomField tcField = customFieldManager.getCustomFieldObject("customfield_17944")
CustomField rrField = customFieldManager.getCustomFieldObject("customfield_17941")
CustomField sizeField = customFieldManager.getCustomFieldObject("customfield_17942")
CustomField svField = customFieldManager.getCustomFieldObject("customfield_19311")
String bvValue = issue.getCustomFieldValue(bvField).toString()
String tcValue = issue.getCustomFieldValue(tcField).toString()
String rrValue = issue.getCustomFieldValue(rrField).toString()
String sizeValue = issue.getCustomFieldValue(sizeField).toString()
String svValue = issue.getCustomFieldValue(svField).toString()
double sizeInt = Integer.parseInt(sizeValue)
double rrInt = Integer.parseInt(rrValue)
double tcInt = Integer.parseInt(tcValue)
double bvInt = Integer.parseInt(bvValue)
double svInt = Integer.parseInt(svValue)
def svTotal = ((bvInt + tcInt + rrInt + svInt) / sizeInt) * 100
def totalNull = ((bvInt + tcInt + rrInt) / sizeInt) * 100
def result
if(svInt==1 || 5 || 8 || 13){
result = svTotal
}else {
result = totalNull
}
return result
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.ComponentAccessor
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField bvField = customFieldManager.getCustomFieldObject("customfield_17937")
CustomField tcField = customFieldManager.getCustomFieldObject("customfield_17944")
CustomField rrField = customFieldManager.getCustomFieldObject("customfield_17941")
CustomField sizeField = customFieldManager.getCustomFieldObject("customfield_17942")
CustomField svField = customFieldManager.getCustomFieldObject("customfield_19311")
String bvValue = issue.getCustomFieldValue(bvField).toString()
String tcValue = issue.getCustomFieldValue(tcField).toString()
String rrValue = issue.getCustomFieldValue(rrField).toString()
String sizeValue = issue.getCustomFieldValue(sizeField).toString()
String svValue = issue.getCustomFieldValue(svField).toString()
double sizeInt = Integer.parseInt(sizeValue)
double rrInt = Integer.parseInt(rrValue)
double tcInt = Integer.parseInt(tcValue)
double bvInt = Integer.parseInt(bvValue)
double svInt = Integer.parseInt(svValue)
def svTotal = ((bvInt + tcInt + rrInt + svInt) / sizeInt) * 100
def totalNull = ((bvInt + tcInt + rrInt) / sizeInt) * 100
def result
if(svInt==1 || 5 || 8 || 13){
result = svTotal
}else {
result = totalNull
}
return result
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No. The if statement is the validation. The code I gave before
if (fieldValue3) { total += fieldValue3 }
in English is:
If you have anything at all for fieldValue3, then add it to total
(This will still fail if fieldValue3 is not a number, but the main thing here is that the if is checking to see if there's anything there at all)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry, our comments crossed over. In your code, you're still not checking that you have a value before you try to work with it.
The "if" I've given needs to check a value is there before any conversions or sums.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.