Hello -
In my Jira project I am attempting to configure a Script Field that involves some basic math. There are 2 custom fields that are involved: "Amount Requested" and "Amount Returned." The Script Field is called "Amount Available."
What I want to happen is for the Script Field (Amount Available) to continuously calculate:
(Amount Returned) - (Amount Requested) = Available Amount
I currently have this script:
import com.atlassian.jira.component.ComponentAccessor
def aval = getCustomFieldValue("Amount Requested")
def bval = getCustomFieldValue("Amount Returned")
return bval - aval
So far it seems like this script is calculating the correct math. There is one step that I want to add to take this further though. Is there a way for me to set the Amount Available field to 1000, and then continue with the scripted equation?
In short, what I am ultimately attempting to achieve is:
1000 + (Amount Returned) - (Amount Requested) = Available Amount
I am at a loss as to what I can do here (if anything). Would appreciate any help I can get. Thanks.
hello Michael.
why not use another variable ?
def initialvalue = 1000
then at the end return initialvalue +bval -aval
?
Agreed. If it's a static value then you should just addit to the equation.
Unless I'm missing something...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I apologize for bringing this up again, but I am running into a new problem. The following is the script I have so far:
import com.atlassian.jira.component.ComponentAccessor
def aval = getCustomFieldValue("Amount Requested") as Double
def bval = getCustomFieldValue("Amount Returned") as Double
// check both fields contain valid numeric values and if not set them to 0
if (aval == null) {
aval = 0
}
if (bval == null) {
bval = 0
}
if (aval != null && bval != null){
return 1000 - aval + bval
} else {
// return to some code to indicate a null value in one of the fields
return 0
}
With 1 Issue uploaded the equation works great, however, as I upload more Issues a problem occurs. Each Issue I upload adds 1000 more to the Amount Available field.
Quick example: The first Issue I uploaded with the Amount Requested = 100 and Amount Returned = 10 gave me Amount Available = 910.
I uploaded the second Issue and the Amount Available immediately went up to 1910.
Would there be any way possible to have this 1000 in Amount Available only occur 1 time, and remain static for additional Issues that get uploaded?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@MAG-II - I'd try this:
import com.atlassian.jira.component.ComponentAccessor
def aval = getCustomFieldValue("Amount Requested") as Double
def bval = getCustomFieldValue("Amount Returned") as Double
// check both fields contain valid numeric values and if not set them to 0
if (aval == null) {
aval = 0
}
if (bval == null) {
bval = 1000
}
if (aval != null && bval != null){
return bval - aval
} else {
// return to some code to indicate a null value in one of the fields
return 0
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah right I was doing that, but it did not appear to be adding up. After a long time of testing / trying to figure out what the problem was I realized that there was some kind of caching issue. It is working now. Thank you for you help.
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.