简体   繁体   中英

How to set the version fields of a JIRA ticket from Groovy

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 eg 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?

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()])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM