which custom field type can be used as an input for a numeric calculation?

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

3 answers

This widget could not be displayed.

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.

This widget could not be displayed.

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()

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

}

Try removing your import and:

def Risk_Severity = getCustomFieldValue("Risk Severity - Select").value as Integer

This widget could not be displayed.

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()

}

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

155 views 2 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you