Similar to the question about Groovy Script compare version picker, I want a scripted field to compare two custom version picker fields within an issue. One field is a multi-select version picker (exists in) and the other is a single-select version picker (found in). Both are required and will always have a value.
If any of the version IDs listed in “ExistsIn” are less than the single version ID set for “FoundIn”, the result should be true.
I couldn’t figure out how to calculate "ExistsIn" < “FoundIn”, so I tried this, which kind of works:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.fields.CustomField CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); CustomField FoundIn = customFieldManager.getCustomFieldObject("customfield_11800"); CustomField ExistsIn = customFieldManager.getCustomFieldObject("customfield_10007"); if (ExistsIn != FoundIn) return "Yes" else return null
The issues are still reindexing, but it looks l like they’re all being set to Yes, even when the value in both fields is identical.
As an added challenge, I want to exclude issues that have a certain version ID set for “ExistsIn”. (ExistsIn != “17407”)
Any help would be appreciated!
Right now, you're comparing the custom field objects themselves. You'll want to use FoundIn.getValue(issue)
and ExistsIn.getValue(issue)
to get the actual value of those fields.
After that, checking for your pre-determined version ID should be pretty straightforward.
Thanks Jonny! Getting closer. I got the version picker comparison working with this:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.fields.CustomField CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); CustomField FoundIn = customFieldManager.getCustomFieldObject("customfield_11800"); CustomField ExistsIn = customFieldManager.getCustomFieldObject("customfield_10007"); if (FoundIn.getValue(issue) != ExistsIn.getValue(issue)) return "Yes" else return null
I'm still struggling to get the version ID condition working.
I tried using this, using both the version ID and the version name:
if (ExistsIn.getValue(issue) != "17407") return "Yes" else return null
The issue preview is returning "Yes" for issues where ExistsIn = 17407. What am I doing wrong, and how can I combine this condition with the FoundIn != ExistsIn clause?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Version Picker fields will return a VersionImpl object when the getValue method is called. The name
property has the text that appears in JIRA, the id
has the numeric ID as a Long. Use them as appropriate. Calling toString
on it will coerce it to its name as a string.
By the way, for comparing two version numbers, there's some good ideas for Java which would port to Groovy. My favorites are just tokenizing the strings or using Maven's comparator. Similar groovy-specific solutions exist as well. That presumes your naming convention follows the "Major.Minor.Revision" style. If you're using "Version 1.0", "Version 2.3", etc. style, you'll need something different.
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.