I am looking at the option of using Script listener to update the sub task when the Fix version of the Parent is updated. Below is the script for it, my only problem with the script is, it does not copy the Fix Version of the parent when creating a sub task, but when I change the Fix version of parent later, then it works and reflects on the Sub Task.
EVENT - Issue created, Issue updated
import com.atlassian.jira.component.ComponentAccessor
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
IssueManager issueManager = ComponentAccessor.getComponent(IssueManager.class)
Issue updatedIssue = event.getIssue()
Collection<Version> fixVersions = new ArrayList<Version>()
fixVersions = updatedIssue.getFixVersions()
Collection<Issue> subTasks = updatedIssue.getSubTaskObjects()
subTasks.each {
if (it instanceof MutableIssue) {
((MutableIssue) it).setFixVersions(fixVersions)
issueManager.updateIssue(event.getUser(), it, EventDispatchOption.ISSUE_UPDATED, false)
}
}
Can someone please help :) Thank you
It works correctly. In the script you look for subtasks, that is why your script works only for the parent task. Your scripts for the create subtask and update parent task must be different. For the create event you should get the parent of the issue, get the fix version and save it to the event issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Alexey Matveev Hello. Thanks for the comment. So, I need to create another listener to copy the Fix Version of parent when a sub task is being created ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can either create another listener or use the same one. But you need to define in the listener whether the event issue is a sub-task or the parent task and then code different logic.
For parent task you would iterate over sub-tasks and set the fix version for the sub-tasks (that is what your script does right now)
For subtasks you would find the parent task, take the fix version and set the fix version for the sub-task.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I came across the below script for a similar scenario. Would this work for my requirement. (Not from a developmental background, so had trouble writing one myself)
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
if(!event.issue.isSubTask() && !event.issue.getSubTaskObjects()){
return
}
def customFieldManager = ComponentAccessor.customFieldManager
if(event.issue.isSubTask()) {
def parent = event.issue.getParentObject()
def status = parent.status.name
def parentStatus = customFieldManager.getCustomFieldObjectByName("Fix Version/s")
def changeHolder = new DefaultIssueChangeHolder()
parentStatus.updateValue(null, event.issue, new ModifiedValue(parentStatus.getValue(event.issue), status), changeHolder)
}
if(event.issue.getSubTaskObjects()){
def subtasks = event.issue.getSubTaskObjects()
def status = event.issue.status.name
subtasks.each {
def parentStatus = customFieldManager.getCustomFieldObjectByName("Fix Version/s")
def changeHolder = new DefaultIssueChangeHolder()
parentStatus.updateValue(null, it, new ModifiedValue(parentStatus.getValue(it), status), changeHolder)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try to log info into the atlassian-jira.log and have a look if it works as you expect. You can log with log.error("variable: " + variable)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Alexey Matveev Hello Alexey, can you please validate the below script, (I am so sorry for troubling you so much)
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
def field = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Fix Version")
//def field = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("fixVersion")
def parentMyFieldValue = issue.parentObject.getCustomFieldValue(field)
def changeHolder = new DefaultIssueChangeHolder();
field.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(field), parentMyFieldValue),changeHolder);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.