In JIRA 6.4.6, I am trying to create a script listener using Script Runner using an inline script. Basically, if the Affects Version/s is updated on a parent issue, I want to update all of its subtasks with those same values in Affects Version/s, as well.
This is the script that I have so far. It works as is, but I don't know how to actually set the Affects Version/s field value on the subtasks.
import com.atlassian.jira.component.ComponentAccessor def affectsVersions = issue.getAffectedVersions() def commentManager = ComponentAccessor.getCommentManager() def user = ComponentAccessor.getJiraAuthenticationContext().getUser() def subtasks = issue.getSubTaskObjects() subtasks.each { commentManager.create( it, user, "New Affects Version/s: " + affectsVersions, false) //works correctly up to here. don't know how to set Affects Version/s field value }
The comment I create shows up on all of the subtasks correctly. What method(s) should I use to set the field value? I'm still fairly new to groovy scripting and the JIRA API documentation and I'm failing to locate the methods I need.
Thanks for your help!
I recently did that for FixVersion, but using a groovy class file because my ScriptRunner/JIRA doesn't let me do inline custom listeners. I modified the code from here, to give credit where it is due:
I had to modernize it a little, plus fixed it so it would null out values:
package com.myorg.listeners import org.apache.log4j.Category import com.atlassian.jira.ComponentManager import com.atlassian.jira.event.issue.AbstractIssueEventListener import com.atlassian.jira.event.issue.IssueEvent import com.atlassian.jira.issue.Issue import com.atlassian.jira.project.version.Version import com.atlassian.jira.config.SubTaskManager import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.event.type.EventDispatchOption import java.util.ArrayList import java.util.Collection class SyncParentFixVersionToSubTask extends AbstractIssueEventListener { Category log = Category.getInstance(SyncParentFixVersionToSubTask.class); SubTaskManager subTaskManager = ComponentManager.getInstance().getSubTaskManager(); @Override void workflowEvent(IssueEvent event) { try { Issue eventIssue = event.getIssue(); if ( !eventIssue.getIssueTypeObject().isSubTask() ) { List changeItems = event.getChangeLog().getRelated("ChildChangeItem"); if( changeItems.any {it.get('field')=='Fix Version'} ) { Collection<Version> fixVersions = new ArrayList<Version>(); fixVersions = eventIssue.getFixVersions(); Collection<Issue> subTasks = eventIssue.getSubTaskObjects(); if (subTaskManager.subTasksEnabled && !subTasks.isEmpty()) { IssueManager issueManager = ComponentManager.getInstance().getIssueManager(); Collection<Issue> _subTasks = eventIssue.getSubTaskObjects(); _subTasks.each { 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 SyncParentFixVersionToSubTask" log.debug (ex.getMessage()) } } }
@Jeremy Gaudet Thanks for the above script but looks like there are changes to methods in JIRA 7.1.8. We are using 7.1.8 and I am not able to make the following code work:
What I am trying to do is pretty much the same what your script above does - Update the fixVersion on all the subtasks when the fixVersion on the parent changes.
it.setFixVersions(fixVersions);
issueManager.updateIssue(event.getUser(), it, EventDispatchOption.ISSUE_UPDATED,
false
);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.