I am trying to use a groovy script to calculate the value of one single select numeric custom field multiplied by another single select numeric custom field and im totally stuck.. any help?
def Impact = getCustomFieldValue(“Impact”)
def Probability = getCustomFieldValue(“Probability”)
if (Impact) {
return Impact * Probability
}
else {
return null
}
You can try using the below code. Firstly, I am getting the custom field by name, followed by getting the values as Double. If both the values are > 0, only then perform multiplication.
import com.atlassian.jira.component.ComponentAccessor
def customfieldManager = ComponentAccessor.getCustomFieldManager()
def impact = customfieldManager.getCustomFieldObjectByName("Impact");
def probability = customfieldManager.getCustomFieldObjectByName("Probability");
def impactValue = issue.getCustomFieldValue(impact) as Double
def probablityValue = issue.getCustomFieldValue(probability) as Double
if(impactValue > 0 && probablityValue > 0) {
return impactValue * probablityValue;
} 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.
You actually didn't specify which app you are using to run this script. ScriptRunner? JMWE? Another app? It actually makes a difference.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi David, it was ScriptRunner!
I've fixed the issue i was having, thanks to everyone for their support.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Peter,
I have used SIL to perform calculations. Please refer below example. You may try below link for groovy
number planneda = argv["Planned_A"];
number plannedb = argv["Planned_B"];
number plannedtotal = pmplanned*seplanned;
lfSet("Total Planned",plannedtotal );
http://myagileplm.com/question/groovy-script-to-multiply-two-numeric/
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.