Hey all!
So heres the scenario. I have a custom field in sub tasks called "expense" and a field in a story "called total" expense. When a sub-task is created the user will enter the expense. I want to have all the expenses summed up and totaled in the "total expense" field in the story. As sub tasks are added that total expense field needs to update.
Anyone have any crazy ideas (or not so crazy ideas) to get this accomplished?
My issue is i don't know the first thing about writing scripts so i wouldn't know where to begin.
Hi @Scott Federman,
One other option for you to consider is the Power Scripts add-on. With much fewer lines of code, you can quickly and easily sum up fields in sub-tasks and show the result in story.
We've put together a quick 5 min video showing you how to set this all up. We've also included the sample script we used (it's performing simple subtraction, but you can change it to summation easily) so you can just copy and paste it to try it yourself.
Hope this helps!
Johnson
Alright Alexey,
I have one final step in this project i could use your wizardry on.
I have another issue type called Project Budget. This has a custom number field call "Budget". What i want to do is link the story issue type to the project budget issue type using the "relates to" link type. Then i want to subtract the expense field we just created from the budget field in the project budget and return a "Remaining Budget" in the project budget issue type.
Is that possible?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
What plugin do you have for writing scripts?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alexey,
I'm open to plugins. Script Runner, Powerscripts, etc. I will purchase the plugin based on getting this to work:)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your Jira version is Server, is not it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes server 7.5.0. We will be moving to cloud however in February
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Do you know that Power Scripts exists only for Jira Server and Adaptivist Scriptrunner is limited for Cloud? And you would need another script for Cloud. Do you still need the script for Jira Server?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes i would still need the script for server to satisfy the need now, but when i move to cloud i will need to update it accordingly.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok.
0. Install Scriptrunner
1. Create custom field expense of number type
2. Create custom field total expense of scripted field type
3. Go to AddOns find scripted fields and push edit for total expense field.
4. Choose number template
5 paste the following script
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)};
5. put total expense on the view screen of a task
6. put expense field on create, edit and view screen of sub-task.
7. fill expense field for a sub-task and total expense for the task will calculated automatically.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
it does not seem to be pulling the expenses. I enter the expense in the sub task and the total expense field doesnt populate
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I checked on my Jira Instance and it is working. Not sure why it is not working on yours
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just to make sure im one the same page.
I created a new scripted custom field called "Total Expense" and placed it on the story view screen.
I went to script runner and found scripted fields where i located the Total expenses field.
I then selected the the number field option from the template drop down.
then i copied and pasted the following.
I created a new sub task and entered the number in the expense field.
I refreshed the story and....nothing happened:(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is the error i get in the log
The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.
2017-11-30 13:20:41,309 ERROR [customfield.GroovyCustomField]: ************************************************************************************* Script field failed on issue: OPS2-80, field: Total Expense java.lang.NullPointerException at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:896) at com.atlassian.jira.issue.Issue$getCustomFieldValue$5.call(Unknown Source) at Script9$_run_closure1.doCall(Script9.groovy:5) at Script9.run(Script9.groovy:5)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did you create expense field? how is it called expense or Expense? it is case sensitive. In the script it is expense
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.
I update the script with the uppercase e and it works:) Thank you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It is possible. It would be simpler if you made a field "Remaining Budget" which is a scripted field. Then in this field you would iterate over necessary links with a code like this
def issueLinks = ComponentAccessor.issueLinkManager.getInwardLinks(issue).findAll{it -> it.getIssueLinkType().getName().equals("relates to") }
Then you would iterate over issue links and get all issues with issue type Story and then for each story you would sum sub-task estimates. Then you would substract summed estimates from the budget field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Im not sure i follow. I create a scripted field in the project budget issue type and use the script below?
def issueLinks = ComponentAccessor.issueLinkManager.getInwardLinks(issue).findAll{it -> it.getIssueLinkType().getName().equals("relates to") }
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.