You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
This should be very similar for you advanced scripters: I have two Number fields ("Field A", "Field B") that I want to sum in a "Total" field. I have script runner. Can someone post for me the entire script that I could use to make this work? I'm a weak scripter and need the entire script, not just excerpts. Thanks you so much to anyone who can help.
This is similar to the question posted here, but I need someone to post the complete working script for me, which doesn't seem to have occurred in this entry: https://community.atlassian.com/t5/Adaptavist-questions/SUM-the-values-of-2-Number-Custom-Fields-in-a-3rd-Custom/qaq-p/1248782#U2122588
For a full script to be developed, you'll need to be a lot more explicit with your requirements.
Where and when you want this to happen will have a pretty significant impact on how such a script would be implemented.
Some preliminary questions:
Hi there, Thank you for replying:
1. Yes
2. Yes
3. No
4. No preferably, but doesn't really matter.
5. Real time preferred.
6. Yes, that would be acceptable.
7. I need A and B to either default to 0 or be allowed to be empty. In either case Total should total any field that has a value above 0.
Wow, this is why I reach out for help. @Peter-Dave Sheehan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Because of your response to #5, my recommendation is to use a behavior script.
This way, the Total field will be visible on create/edit screens, but in a read-only fashion and calculate in real time as you change either Field A or FieldB.
The one CON to this option is that Field A and Field B will no longer be editable in-line. When you click on the pencil icon on one of those fields, the full edit screen will pop up.
Here is the script you will need:
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def fieldA = getFieldByName('Field A')
def fieldB = getFieldByName('Field B')
def fieldTotal = getFieldByName('Total')
def valueA = (fieldA.value ?: 0) as Number
def valueB = (fieldB.value ?: 0) as Number
def totalValue = valueA + valueB
fieldTotal.setFormValue(totalValue)
Now, go to Scriptrunner Behaviours
Here is what it looks like in my environment (I used 3 arbitrary number fields for example)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You're incredible. My favorite person in the world today! I will get to work on this now.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What Peter is saying is absolutely correct and to consider.
Here is an exampel for a scripted field which probably is something you are looking for.
//
// Gesamtaufwand in PT
//
import com.atlassian.jira.component.ComponentAccessor;
import org.apache.log4j.Logger
/*
## Custom Field IDs ueberpueft am 07.05.2021
##
## Geplanter Aufwand FB = customfield_13666 - in allen Umgebungen gleiche ID
## Geplanter Aufwand ZI = customfield_13664 - in allen Umgebungen gleiche ID
## Aufwand sonstiges in PT = customfield_13681 - in allen Umgebungen gleiche ID
## Gesamtaufwand = customfield_15702
*/
Integer[] arrCustomfieldId = [
13666,
13664,
13681
]
int intSummeVerplant = 0;
for (int intCustomfieldId : arrCustomfieldId){
try {
intSummeVerplant += (Integer)issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_" + intCustomfieldId));
} catch(Exception e) {
log.warn("Catching Exception" + "\ne");
}
}
return (intSummeVerplant);
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.