Hi,
Our situation is that we have a few developers who would like to break Story Points into
Dev and QA Story Points. I would like to sum Dev and QA in the Story Points field using Behaviors.
I only want Story Points to be the sum of Dev and QA if either value is not null (since some users do not want to split the Story Points).
I put this code in both Dev and QA fields.
Only works if both Dev and QA are not null, then the sum is calculated in Story Points. However, I tried to make it so if one of the fields is not null and the other is null, Story Points is the value of the not null field. This does not work.
def qa = getFieldById("customfield_11034") def dev = getFieldById("customfield_11033") def sum = getFieldById("customfield_10103") def qavalue = qa.getValue() as Integer def devvalue = dev.getValue() as Integer if (qavalue != null && devvalue == null) { sum.setFormValue(qavalue); } else if (devvalue != null && qavalue == null) { sum.setFormValue(devvalue); } else if (qavalue != null && devvalue != null) { return sum.setFormValue(devvalue + qavalue); } else return null;
For both of them can you not just do:
def qavalue = qa.getValue() as Integer ?: 0
Then they will both non-null, and you can just add them and avoid the null-checking.
Or use what Nic said but you do need the setFormValue.
Even neater than my code.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks guys,
I put this
def qa = getFieldById("customfield_11034") def dev = getFieldById("customfield_11033") def sum = getFieldById("customfield_10103") def qavalue = qa.getValue() as Integer ?: 0 def devvalue = dev.getValue() as Integer ?: 0 return sum.setFormValue(qavalue + devvalue)
in the Validation Script for both QA and Dev fields. The null value doesn't seem to be setting to zero.
Maybe I am doing something wrong.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You don't need to return it but should not make a difference.
Can you describe when it should be set to zero?
Your question wasn't really clear, is that you want the sum to be zero if either field is zero?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If so change the last line to
if (qavalue && devvalue) { sum.setFormValue(qavalue + devvalue) } else { sum.setFormValue(0) }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In our situation, we only want the sum (Story Points) to be set if:
If both, qavalue and devvalue are null, then sum value should not be set based on these fields.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Apologies for my incorrect "return" statements earlier.
I think you're very close, but need an empty field instead of a 0 when both source fields are empty. So:
def qavalue = qa.getValue() as Integer ?: 0 def devvalue = dev.getValue() as Integer ?: 0 if (qavalue || devvalue) { sum.setFormValue(qavalue + devvalue) } else { sum.setFormValue() }
However... I'm not sure of my coding here - that second "setFormValue" is trying to say "set field to empty", but I don't know if () is the right way to do it - it might be ("null") or possibly some other function call like sum.clearFormValue()
(I just did a ScriptRunner introduction course - there wasn't much coding and four of the modules were nothing new, but the fifth module was on "Behaviours" and confirmed that I really don't know how to write for that)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
IIRC:
sum.setFormValue("")
I missed the training course unfortunately
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm trying to do something similar and am VERY new to Groovy (also, don't have a dev background but I'm learning...by trial and error).
We have Behaviours and I want to sum the value of two fields in a third filed so I assumed adding a script to those fields would be easiest. I want the scripts to run when any of the two "input fields" are updated. Here's my feeble attempt based on online research/trying...
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;
int bizvalue = customFieldManager.getCustomFieldObjectByName( "User/Biz Value") as Integer;
int time = customFieldManager.getCustomFieldObjectByName( "Time Criticality" ) as Integer;
int costofdelay = customFieldManager.getCustomFieldObjectByName( "Cost of Delay" ) as Integer;
cost = sum.setFormValue(bizvalue + time)
setCustomFieldValue(costofdelay, cost);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I keep getting a few errors at the end of the console when I use this script and I'm kind of at a roadblock with figuring out what to do...help?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
From your first if, try:
def result = 0 if (qavalue) { result += qavalue } if (devalue) { result += devvalue } if ( result != 0 ) { return result } else return null
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.