It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Custom update listener to set subtask's fix-version Edited

Hi all,

I'm developing custom listener which will update subtask's fix version to same value as it's parent issue. 

Currently we are using post-function in workflow in order to set subtask's fix version according to parent on subtask creation. This however doesn't cover cases when subtask already exists and parent's fix version gets updated. New value from parent task is not propagated to subtask.

I'm using script runner and I'm creating 'Custom lisatener', for my specific project and specified Event: 'Issue Updated'. I added script as following:

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.project.version.Version
import org.apache.log4j.Logger

class CopyFixVersionFromParentToChild extends AbstractIssueEventListener {
    Logger log = Logger.getLogger(CopyFixVersionFromParentToChild.class);
    SubTaskManager subTaskManager = ComponentAccessor.getComponent(SubTaskManager.class)
    IssueManager issueManager = ComponentAccessor.getComponent(IssueManager.class)

    @Override
    void issueUpdated(IssueEvent event) {
        log.warn("\nIssue updated!!!\n")
        try {
            Issue updatedIssue = event.getIssue()
            if (updatedIssue.issueTypeObject.name == "Parent issue type") {
                Collection<Version> fixVersions = new ArrayList<Version>()
                fixVersions = updatedIssue.getFixVersions()
                Collection<Issue> subTasks = updatedIssue.getSubTaskObjects()
                if (subTaskManager.subTasksEnabled && !subTasks.empty) {
                    subTasks.each {
                        if (it instanceof MutableIssue) {
                            ((MutableIssue) it).setFixVersions(fixVersions)
                            issueManager.updateIssue(event.getUser(), it, EventDispatchOption.ISSUE_UPDATED, false)
                        }
                    }
                }
            }
        } catch (ex) {
            log.debug "Event: ${event.getEventTypeId()} fired for ${event.issue} and caught by script 'CopyVersionFromParentToChild'"
            log.debug(ex.getMessage())
        }
    }
}

Problem is, that it doesn't work. I'm not sure whethe rit's problem that my script logic is encapsulated inside class. Do I have to register this in some specific way? Or am I using script runner completely wrong and I'm pasting this script to wrong section? I checked code against JIRA API and it looks like it should work, my IDE doesnt show any warnings/errors.

Also, could anyone give me hints on where to find logging output from custom scripts like this? Whatever message I put into logger, I seem to be unable to find anywhere in JIRA logs (although I'm aware that script might not work for now).

Any response is much appreciated guys, Thanks.

Martin

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you