I currently have a (script-runner) scripted field in an "Order Request" called "Total Order Expense($)" which calculates the sum of all linked "line item orders".
I have added an RMA issue type which is also linked to the "Order Request" which is how we track returned items. This has a calculated field called "Return Amount" which needs to be subtracted from the "Total Order Expense ($) field in the order request.
Below is the script i use to calculate the "Total Order Expense ($) now. How would I include the ability to subtract the "Return Amount" from that number?
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
def csExpense = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Expense")
return issue.getSubTaskObjects().sum{it ->((Issue) it).getCustomFieldValue(csExpense)};
Hey @Scott Federman
Here are some examples of multiplying, adding, subtracting and dividing using groovy.
You'll need to define each custom field you need. See below example. Let me know if it helps.
def customfieldnameCF = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Custom Field Name")
def customfieldvalueCFVal = issue.getCustomFieldValue(customfieldnameCF) as Double
def calc = ((customfieldvalueCFVal*3) - customfieldvalueCFVal + customfieldvalueCFVal)/8
def calcc = customfieldvalue1CFVal - customfieldvalue2CFVal - customfieldvalue3CFVal
Yup sort of. Pardon my ignorance. But which custom field names do I put where?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm here to help!
Depending on where and how you're returning the value for the Expense, it should work like the below. Might need some tweaking, I wasn't able to test it to make sure it works.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
def csExpense = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Expense")
return issue.getSubTaskObjects().sum{it ->((Issue) it).getCustomFieldValue(csExpense)}
def returnamountCF = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Return Amount")
def returnamountCFVal = issue.getCustomFieldValue(returnamountCF) as Double
def calc = returnamountCFVal - csExpenseCFVal
return calc
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Excellent! I tried it out and its only returning the "Expense" value from the line item issue, but it is not subtracting the "Return Amount" from the RMA issue.
it should be : Total Order Expense $ (Order Request Issue Type) = Expense (line Item Order Issue Type) - Return Amount (if available) (RMA Issue Type)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is the return amount is in another issue type?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes it is
Issue type Field
Order Request Total Order Expense $
Line Item Order Expense
RMA Return Amount
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Brittany Wispell I tried monkeying with the script a bit and still no luck:(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @Scott Federman
I've got a couple of SR experts helping with this. Since the custom fields are in different issue types it's a little more complex than I was expecting. I will try to get back to you tomorrow! Sorry for how long it's taking.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.