script in Issue updated event stop works after jira update


We have a script that runs on issue updated event. This script just update Fix Version of sub tasks with the Fix Version of the issue.

When we update Fix Version of an issue, it appends this field with the parent version too (we use greenhopper).

After we upgrade to jira 5.2.5, the script stops update with the parent version. It only update with version.

If we run the script in the Script Runner, it works fine.

Can you help us?

4 answers

1 accepted

I fixed using the getParentObject() from each event.issue.getSubTaskObjects() object instead of event.issue.

package com.libgroovy

import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Category
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue

class AtualizarFixVersion extends AbstractIssueEventListener {

    void workflowEvent(IssueEvent event) {
        Category log = Category.getInstance(AtualizarFixVersion.class)
        log.debug "=============================Inicio do script AtualizarFixVersion ============================"
        if ((!event.issue.isSubTask()) && (event.issue.getSubTaskObjects() != null)) {
            def indexManager = ComponentAccessor.getIssueIndexManager()
            def issueManager = ComponentAccessor.getIssueManager()

            for (Issue issue in event.issue.getSubTaskObjects()) {
                issue = issue as MutableIssue;
                //*****here I changed the event.issue to issue.getParentObject()******


                boolean wasIndexing = ImportUtils.isIndexIssues();

                log.debug " Issue: ${event.issue}\n Issue fix version: ${event.issue.getFixVersions()}\n Parent: ${issue.getParentObject()}\n Parent fix version: ${issue.getParentObject().getFixVersions()}\n Child Issue: ${issue}\n Child fix version: ${issue.getFixVersions()}"
            log.debug "==========================================Fim do script========================================="

Thank you!

I ran into a similar issue, but I can't recall how I fixed it. Nonetheless, here's my own script that ensures sub-tasks version always match their parent.

package com.custom
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.project.version.Version
import com.atlassian.jira.event.type.EventDispatchOption
import org.apache.log4j.Category
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager
import com.atlassian.jira.issue.history.ChangeItemBean
import java.util.Calendar
import java.util.Date
import java.sql.Timestamp

class TaskVersionListener extends AbstractIssueEventListener {
    Category log = Category.getInstance(TaskVersionListener.class)
    void issueUpdated (IssueEvent event) {
	log.debug ("---- TaskVersionListener starts -----")
	log.debug ("issue: ${event.issue} || task: ${event.issue.isSubTask()}")
	// method configuration
	Calendar cal = Calendar.getInstance()
	cal.add(Calendar.SECOND, -30)
	Date date = cal.getTime()
	Timestamp threshhold = date.toTimestamp()
	IssueManager issueManager = ComponentAccessor.getIssueManager()
	UserManager userManager = ComponentAccessor.getUserManager()
	ChangeHistoryManager changeHistoryManager = ComponentAccessor.getChangeHistoryManager()

	if (!event.issue.isSubTask()) {
		List <ChangeItemBean> changeItemBeans = changeHistoryManager.getChangeItemsForField(event.issue,"Fix Version")
		changeItemBeans.each { item ->
			log.debug ("Fix Version created at ${item.getCreated()} with threshhold of $threshhold")
			if (item.getCreated().after(threshhold)) {
				log.debug ("green light for item above!")
				event.issue.getSubTaskObjects().each { t ->
					if (!t.getStatusObject().getName().equals("Done")) {
						MutableIssue myIssue = t
						issueManager.updateIssue(userManager.getUser("automation"), myIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
	} else {
		List <ChangeItemBean> changeItemBeans = changeHistoryManager.getChangeItemsForField(event.issue,"status")
		changeItemBeans.each { item ->
			log.debug ("created at ${item.getCreated()} with threshhold of $threshhold")
			if (item.getCreated().after(threshhold) && item.getFromString().equals("Done")) {
				log.debug ("green light for item above!")
				MutableIssue myIssue = event.issue
				issueManager.updateIssue(userManager.getUser("automation"), myIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
	log.debug ("---- TaskVersionListener ends ------")

Thank you,

I'm doing the same thing but the time verification. I'm applying an reindex on subtasks too.

Thank you,

I'm doing the same thing but the time verification. I'm applying a reindex on subtasks too.

I fixed replacing event.issue.getFixVersions for a call to getParentObject() on each sub task object of the issue.

The log was:

Issue: WTES-33
Issue fix version: [Version 1.01]

Parent: WTES-33
Parent fix version: [Version 1.0, Version 1.01]

Child Issue: WTES-34
Child fix version: [Version 1.0, Version 1.01]

Issue and Parent are the same object, but the fix version value is different.

We'd need more info other than it doesn't work... eg any errors in logs? Have you added some debug so you can see what your script is trying to do?

I have a version called "Release 1.01". It's a child version of "Version 1.0".

When I update the issue fix version, setting with "Release 1.01"(the child) automatically it puts "Version 1.0"(the parent) on Fix Version field separeted by comma.

On Jira prior version, when I perform this, the script set subtask fix version with "Version 1.0, Release 1.01".

Now it's just set with "Release 1.01".

The script update the subtask issue, but on log when I run event.issue.getFixVersions() it only returns "[Release 1.01]" instead "[Version 1.0, Release 1.01]".

The script is running before set the Parent version.

Before we update jira it didn't happen.

The log does not report any error.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 13, 2019 in Marketplace Apps

Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page


263 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you