Update Issues

Updating an issue is equivalent to doing Edit Issue in the user interface.

You can update an issue as follows:

In this example we're updating the summary of an issue and setting the description.

            def issue = Issues.getByKey('ABC-1')
             
            issue.update {
                setSummary('an updated summary')
                setDescription('hello *world*')
            }
Copy

The image example below shows that you can update multiple fields at once: 

Image showing how you update issues with HAPI

The issue variable above is a standard com.atlassian.jira.issue.Issue. So you can update an issue like this anywhere you have a com.atlassian.jira.issue.Issue object.

Avoiding notifications and event dispatches

If you are bulk updating issues you may not want other users to receive notifications of this update. You can stop an event from being fired, and emails being sent, as follows:

groovy
import com.atlassian.jira.event.type.EventDispatchOption issue.update { setSummary('New summary') setEventDispatchOption(EventDispatchOption.DO_NOT_DISPATCH) setSendEmail(false) }

Working with post-functions

When working with a transitioning issue, for example within a scripted post-function, you should generally issue.set() instead of issue.update. Using issue.set() modifies the issue in memory during the post-function execution, so changes to the issue occur in the same transaction, without triggering a redundant update. 

Sometimes, for example when in a post-function, you need to change the fields on an instance of an issue without saving the changes to the database. In these cases, you will have an instance of MutableIssue—for example, the issue variable in a workflow post-function.

You can use the same API to set system and custom fields as described below. For example, to add a named fix-version in a post-function:

                issue.set {
                    setFixVersions {
                        add('v2.0')
                    }
                }
Copy

The Jira API provides many setters on MutableIssue, and you can mix and match with ours:

                issue.setSummary('Hello')
                issue.set {
                    setFixVersions {
                        add('v2.0')
                    }
                }
Copy

Check out the Transition Issues page for examples of transitioning issues. 



Related content

On this page