Very easy!

package example.CopyVersionToSubtasks

import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.CustomFieldType
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.ManagerFactory
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.mail.Email
import com.atlassian.mail.server.MailServerManager
import com.atlassian.mail.server.SMTPMailServer
import org.apache.log4j.Category
import org.ofbiz.core.entity.GenericValue
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.project.Project
import com.atlassian.jira.issue.util.IssueChangeHolder;
import com.atlassian.jira.util.ErrorCollection;
import com.atlassian.jira.util.ImportUtils;
import com.atlassian.jira.util.JiraUtils;
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.workflow.WorkflowManager
import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.workflow.WorkflowTransitionUtil
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.project.version.Version
import com.atlassian.jira.project.version.VersionManager
import com.atlassian.jira.event.type.EventDispatchOption

class TaskVersionListener extends AbstractIssueEventListener {
Category log = Category.getInstance(TaskVersionListener.class)

private void copyAffectedVersion(Issue src, MutableIssue dest) {
Collection<Version> affectedVersions = new ArrayList<Version>();
Version myVersion;
Iterator ite = null;
GenericValue gv = null;
ite = src.getAffectedVersions().iterator();
while (ite.hasNext()) {
myVersion = (Version);
gv = myVersion.getGenericValue();

void workflowEvent(IssueEvent event) {
Iterator ite = null;
MutableIssue mi, smi;
boolean updated;

mi = (MutableIssue) event.getIssue();

if (!event.getIssue().isSubTask()) {
// copy version field to the subtasks
ite = mi.getSubTaskObjects().iterator();
while (ite.hasNext()) {
updated = false;
smi = (MutableIssue);
Issue aux = smi;
//if ( aux.getIssueTypeId() == "65" || aux.getIssueTypeId() == "36" ) {
// this copy the affected version from task to subtask. There are other to compare and copy fixVersion and components, but removed from the sample code
if (!mi.getAffectedVersions().equals(smi.getAffectedVersions())) {
log.debug("copy version to subtask");
this.copyAffectedVersion(mi, smi);
updated = true;

if (updated) {
ComponentAccessor.getIssueManager().updateIssue(event.getUser(), smi,
EventDispatchOption.DO_NOT_DISPATCH, false);
//; ?



Posted by:.

One thought on “New groovy Listener to set the same fixversions to all subtasks in JIRA

  1. Thanks for this. I love the regular tips. The above is fine if you have ScriptRunner but since Adaptivist have started charging I wonder is it as popular.

    There is another alternative to what you have suggested – you can try the Quick SubTasks Plugin. Its free and allows you set up rules to create subtasks can copy any of the values from parent task.

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s