Reputation: 331
I'm using JIRA 7.1.4 Server and under Behaviours I'm trying to create a Groovy Initialiser Function for setting default values of form fields, so when the user tries to create a new ticket, some fields are already filled in with default values. This is what I have so far:
import com.atlassian.jira.component.ComponentAccessor
def versionManager = ComponentAccessor.getVersionManager()
def versions = versionManager.getVersionsUnreleased(issueContext.projectObject.id, false)
getFieldById("affectedVersion").setFormValue([versions.first().id])
getFieldById("description").setFormValue([versions.first().id])
When the dialog for creating a new JIRA ticket opens, this script successfully sets the "Description" field to the right version id (only for debugging purposes), but the "Affects Version/s" field remains empty for some reason.
I think the id of the "Affects Version/s" field is OK, because I got it from JQL, so e.g. the following query displays correct information:
project = "--------" and affectedVersion is EMPTY
Therefore I assume that I'm trying to set the value of the version field incorrectly, but cannot figure out the mistake. The above Groovy script is based on this example, but the script might be wrong, and I was not able to find more information about getFieldById
or setFormValue
here either.
Can anyone give a working example of setting JIRA's "Affects Version/s" or "Fix Version/s" fields from Groovy?
Upvotes: 3
Views: 1819
Reputation: 637
If you setting fixversion on issue create step in workflow. You need to put this script into first post function(before issue create).
import com.atlassian.jira.component.ComponentAccessor
def versionManager = ComponentAccessor.getVersionManager()
def versions = versionManager.getVersionsUnreleased(issue.getProjectObject().getId(), false)
issue.setAffectedVersions([versions.first()])
Upvotes: 0