简体   繁体   中英

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. 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. 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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM