I am creating a custom script field using Scriptrunner.
For some reason, when i try to use a variable in a math function (i.e. var1 + var2) it only returns null. If i put in standard numbers (i.e. 9 + 20) then it returns the value.
Here is the code so far, but i plan to add more custom fields once i get this working:
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.customFieldManager
def cfAlignmentScore = customFieldManager.getCustomFieldObjectByName("Infra Alignment Score")
def alignment = issue.getCustomFieldValue(cfAlignmentScore) as int
if (alignment != null) {
return (alignment * 5)
}
else {
return null
}
As a coder, you do not actually know what is in the custom field. Trying to cast it to an int automatically might work if the type of data is compatible, but my guess is that it is not.
Try dropping the "as int" on the "def alignment" line first, and then check what the logs say as well (they will usually catch script errors with something more useful than my guesses)
After removing the "as int", i get the attached error. The custom field type is a single select list.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, that suggests that the field does not contain a number at all. You'll need to work out some code to convert it to one before you can multiply it with another number
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.