I need to find a way to calculate budgets and costs.
The parent would have the budget field and the child would its cost. I need a way to subtract the cost of the child from the budget in the parent so that it shows remaining budget. Budget(P)-Cost(C).
Any help here would be greatly appreciated.
I changed cost to expense (which is no big deal) But budget is a static field. Remaining budget is where the calculation takes place.
A SIL field uses SIL scripts. Would what you are suggesting be a typical numeric field using script runner or something like that?
Well, you asked the question with the JMCF tag, so I assumed you wanted to create a Calculated custom field. So this is what I offered: the script for a JMCF Calculated Number field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Assuming the "parent" issue has linked ("child") issues linked through the "blocks" link type name, and that link type name is the "Outward Description" of the link type on the "Issue Linking" Jira admin page, you can use a calculated number field with the following formula:
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.link.IssueLink;
if (issue.get("Budget") == null)
return null;
Double val = issue.get("Budget");
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField customField = customFieldManager.getCustomFieldObject("customfield_12345"); //change to field ID of the "Cost" field
for (IssueLink il : issue.get("issuelinks")) {
if (il.getIssueLinkType().getOutward().equals("blocks")) { //change to the appropriate "Outward Description"
Issue linkedIssue = il.getDestinationObject();
cost = linkedIssue.getCustomFieldValue(customField);
if (cost!=null)
val = val - cost;
}
}
return val;
Hope this helps,
David
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi David,
Apparently there was an change in requirements.
Budget field(11723)-Expense field (11724)=Remaining Budget field (11721).
(Budget and Expense are number fields and Reamining Budget is a SIL field)
We would be using the linking type "Related" with an outward description of "is related to".
Any help on that one would be massively appreciated.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Scott,
I'm not sure I understand.
With what you described, the code would be:
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.link.IssueLink;
if (issue.get("customfield_11723") == null)
return null;
Double val = issue.get("customfield_11723");
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField customField = customFieldManager.getCustomFieldObject("customfield_11724");
for (IssueLink il : issue.get("issuelinks")) {
if (il.getIssueLinkType().getOutward().equals("is related to")) {
Issue linkedIssue = il.getDestinationObject();
cost = linkedIssue.getCustomFieldValue(customField);
if (cost!=null)
val = val - cost;
}
}
return val;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey David,
I think im close but still having some issues. I changed the cost field to be "Total Expense which is customfield_11746. All the errors cleared except 1.
and it returns the following error
What am i missing here?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Scott,
first of all, you are using ScriptRunner and not JMCF, so the syntax is different.
But anyway, variable names cannot contain spaces, nor be surrounded by quotes. That's your error here.
If you want to use ScriptRunner, you should ask Adaptavist for support.
Cheers,
David
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
ahh got ya. I have both. Ill create a calculated numeric field and see how that goes.
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.