[英]Gathering custom number fields in Groovy, and calculating return result (JIRA script runner)
Getting accustomed to Groovy, I need to gather 2 number custom field values in JIRA, and perform a calculation on those 2 field values, then return that result to another (3rd) custom field using this script. 习惯了Groovy之后,我需要在JIRA中收集2个数字自定义字段值,并对这2个字段值执行计算,然后使用此脚本将该结果返回到另一个(第3个)自定义字段。 But I am still understanding how global and local variables work.
但是我仍然了解全局变量和局部变量是如何工作的。 How can I return the calculation based below to a 'finalResult' field as indicated below, my variables valuePA and valueCA are not recognized in the if/then statement.
我如何将基于下面的计算返回到“ finalResult”字段,如下所示,if / then语句中无法识别我的变量valuePA和valueCA。 I appreciate any feedback!!
我感谢任何反馈!
FormField paidAmount = getFieldByName("Paid Amount")
def valuePA = paidAmount.getValue()
FormField correctAmount = getFieldByName("Correct Amount")
def valueCA = correctAmount.getValue()
//performing logic on values from correctAmount and paidAmount
def finalResult() {
if (valuePA <= valueCA) {
return (valuePA / valueCA) * 100
} else (valueCA < valuePA) {
return ((valueCA - valuePA) / valueCA) * 100
}
}
Then I will take the finalResult and use it to update the 3rd custom field. 然后,我将使用finalResult并将其用于更新第三个自定义字段。
Just pass those values to the function 只需将这些值传递给函数
def finalResult(a, b) {
if (a <= b) {
(a / b) * 100
} else {
((b - a) / a) * 100
}
}
Then 然后
def result = finalResult(valuePA, valueCA)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.