Hi, I am trying to sum three custom number fields and display that total using a scripted field. I've searched tirelessly for solutions and there's loads of great stuff out there but every time I grab something from the forums I receive an error message - I can diagnose to an extent but that causes something else.
The latest code I am trying to use is:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.opensymphony.workflow.WorkflowContext
def aval = getCustomFieldValue("field1")
def bval = getCustomFieldValue("field2")
def cval = getCustomFieldValue ("field3")
// check both fields contain valid numeric values and if not set them to 0
if (aval == null) {
aval = 0
}
if (bval == null) {
bval = 0
}
if (cval == null) {
cval = 0
}
if (aval != null && bval !=null && cval !=null){
return aval + bval + cval}
else{
// return to some code to indicate a null value in one of the fields
return "0"
}
The problem is that it doesn't seem to like the calculation aval + bval + cval and throws up an error:
Anyone able to help me?
Many Thanks
You are fetching the fields as strings, so you need to convert them to double in order sum them up. Adding as Double at the end of your def should do it:
def aval = getCustomFieldValue("field1") as Double
def bval = getCustomFieldValue("field2") as Double
def cval = getCustomFieldValue ("field3") as Double
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.