I have a scripted field that calculates the product of 3 custom number fields. This works fine but I really need to restrict the input to the 3 number fields to only allow a 1,2, or 3 to be entered. I've tried radio buttons and select list but they aren't treated as numbers so then my scripted field doesn't work.
Can anyone suggest how I can restrict the input and have them be recognized as numbers?
Here is my current script:
def Risk_Severity = getCustomFieldValue("Risk Severity")
def Risk_Probability = getCustomFieldValue("Risk Probability")
def Risk_Detectability = getCustomFieldValue("Risk Detectability")
if (Risk_Severity) {
return (Risk_Severity * Risk_Probability) * Risk_Detectability
}
else {
return null
}
Thank you,
Jeannette
Hi jnet,
in order to implement that feature you need to use Behaviour Custom Field too.
Your scripted field should be :
import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.CustomFieldManager; CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); Issue issue = issue; CustomField Risk_Severity = getCustomFieldValue("Risk Severity - Select"); Integer value_Risk_Severity = issue.getCustomFieldValue(Risk_Severity); CustomField Risk_Probability = getCustomFieldValue("Risk Probability"); Integer value_Risk_Probability = issue.getCustomFieldValue(Risk_Probability); CustomField Risk_Detectability = getCustomFieldValue("Risk Detectability"); Integer value_Risk_Detectability = issue.getCustomFieldValue(Risk_Detectability); if(value_Risk_Severity && value_Risk_Probability && value_Risk_Detectability){ return value_Risk_Severity*value_Risk_Probabilityvalue_Risk_Detectability; } return null;
For each numeric custom field, you need to add the following server side script :
FormField aFF = getFieldByName("Your Custom Field Name") def a = aFF.getValue() if(!"1".equals(a) && !"2".equals(a) && !"3".equals(a)){ aFF.setError("Invalid number. Please, specify 1,2 or 3") } else { aFF.clearError() }
There aren't any numeric fields that will work that way.
Your best bet really is your select or radio button approach, coupled with the script runner being a bit more clever - it can convert the numbers displayed to actual numbers.
If my memory is working today, it's something like value.toInteger(), so you could write return (Risk_Severity.toInteger() * Risk_Probability.toInteger()) * Risk_Detectability.toInteger()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This sounds like a good idea but I'm not getting the syntax right. I changed one of my fields to a select list. I've tried the following script and keep getting an error on the first line.
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption.toNumber();
def Risk_Severity = getCustomFieldValue("Risk Severity - Select")
def Risk_Probability = getCustomFieldValue("Risk Probability")
def Risk_Detectability = getCustomFieldValue("Risk Detectability")
if (Risk_Severity) {
return (Risk_Severity.toInteger() * Risk_Probability) * Risk_Detectability
}
else {
return null
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try removing your import and:
def Risk_Severity = getCustomFieldValue("Risk Severity - Select").value as Integer
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As Nic says, toInteger() is fine, or
x as Integer
However I would probably keep them as numeric fields, and just have a validator that the number is an integer between and including 1 and 3.
That will let you do aggregate calculations on the values using script runner, or in jql if it supports it one day.
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.