简体   繁体   English

收集Groovy中的自定义数字字段,并计算返回结果(JIRA脚本运行器)

[英]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.

相关问题 该条件(常规脚本)的返回值是多少? - What is the return value of this conditional (groovy script) 在结果表中计算和插入值 - calculating and inserting values in a result table python收集多个函数的返回值,并在一个非主函数处针对所有函数验证输入 - python gathering return value of multiple function and validate input against all function at one non-main function 基于Groovy Result响应的条件转到 - Conditional Goto based on Groovy Result response 如何使用 JavaScript 语言比较两个对象并返回一个介于 0 和 100 之间的数字,表示相似度的百分比作为结果 - How to compare two objects using JavaScript language and return a number between 0 and 100 representing the percentage of similarity as the result groovy 脚本中的 if-else 和默认条件 - If-else and default condition in groovy script R-计算分配给相同数字的值 - R - calculating values assigned to the same number 如何通过脚本在POSTMAN CollectionRunner中设置失败 - How to set failed in POSTMAN Collection runner via script Python-计算回文数时长时间停止 - Python - long halt while calculating palindrome number 计算 pandas dataframe 中的条目数低于 0 - Calculating number of entries in pandas dataframe below 0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM