Hi all,
We have a custom dropdown field called "Project Group" for Epic, Requirement/User Story and its sub-tasks. Now, we have to manually this field value.
I would like to achieve "Project Group" of Requirement/User Story could inherit the field value from Epic directly, also sub-tasks could inherit the field value from Requirement/User Story.
I did found some similar posts and answers on community, but they do not work for my case. As Requirement/User Story is actually not a real child tickets of Epic, it's the issue in Epic, please see below. Sub-tasks could be children tickets of Requirement/User Story or Epic.
Can anyone please help me writing up the script. Thanks in advance!
Hi @Sasha Sun
For your requirement, you could try something like this:-
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
def issue = event.issue as MutableIssue
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def customFieldManager = ComponentAccessor.customFieldManager
def issueManager = ComponentAccessor.issueManager
def issueLinkManager = ComponentAccessor.issueLinkManager
def projectGroup = customFieldManager.getCustomFieldObjectsByName('Project Group').first()
def epicLink = customFieldManager.getCustomFieldObjectsByName('Epic Link').first()
def projectGroupValue = issue.getCustomFieldValue(projectGroup)
def subTasks = [] as ArrayList<Issue>
if (issue.issueType.name == 'Epic' && issue) {
def links = issueLinkManager.getOutwardLinks(issue.id)
links.each {
def destinationIssue = it.destinationObject as MutableIssue
destinationIssue.setCustomFieldValue(projectGroup, projectGroupValue)
issueManager.updateIssue(loggedInUser, destinationIssue, EventDispatchOption.DO_NOT_DISPATCH,false)
destinationIssue.subTaskObjects.findAll {
subTasks.addAll(it)
}
}
} else if(issue.getCustomFieldValue(epicLink)) {
def links = issueLinkManager.getInwardLinks(issue.id)
links.each {
issue.setCustomFieldValue(projectGroup, it.sourceObject.getCustomFieldValue(projectGroup) )
issueManager.updateIssue(loggedInUser, issue, EventDispatchOption.DO_NOT_DISPATCH,false)
}
} else if(issue.isSubTask()) {
subTasks.addAll(issue)
}
subTasks.each {
def subTask = it as MutableIssue
subTask.setCustomFieldValue(projectGroup, it.parentObject.getCustomFieldValue(projectGroup))
issueManager.updateIssue(loggedInUser, subTask, EventDispatchOption.DO_NOT_DISPATCH,false)
}
Please note, this working sample code is not 100% exact to your environment. Hence, you will need to make the required modifications.
Below is a print screen of the listener configuration:-
What this code does is that if the Project Group field is updated in an Epic, all the issues in the epic, including the sub-tasks, will update the value according to the value set in the Epic.
Also, suppose any new issue or sub-task is created and is associated with the epic. In that case, the Project Group value in the new issue will automatically be set according to the value in the Epic.
I hope this helps to answer your question. :)
Thank you and Kind Regards,
Ram
This is perfect!! Thank you so much!!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Sasha Sun
Great to hear the solution worked for you. :)
Kindly accept the solution provided.
Thank you and Kind Regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ram Kumar Aravindakshan _Adaptavist_
Does this listener handles the case of removing Story from it's Epic?
The wanted result is null for the custom field.
Thank you,
Dorin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @dorin gez
To answer your question, the listener example provided above does not do what you are expecting.
It only updates a particular custom field value in all the issues and sub-tasks of an epic if that specific custom field's value is updated in the parent epic itself.
What you are expecting can be done but will require a different code and listener configuration.
Thank you and Kind Regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The code works perfectly for us, thanks for sharing.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ram Kumar Aravindakshan _Adaptavist_
That script is useful, thanks
However, I've tried to build on and add a level above the Epic based on Advanced Roadmaps "Parent Link"
The hierarchy is : Feature > Epic > Standard issue > Sub-task
The Epic is setp/ updated correctly but not the standard issue and the Sub-task levels
Can you please explain how to include 1 or more levels above the Epic based on Advanced Roadmaps "Parent Link" ?
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ram Kumar Aravindakshan _Adaptavist_
That script is useful, thanks
However, I've tried to build on and add a level above the Epic based on Advanced Roadmaps "Parent Link"
The hierarchy is : Feature > Epic > Standard issue > Sub-task
The Epic is setp/ updated correctly but not the standard issue and the Sub-task levels
Can you please explain how to include 1 or more levels above the Epic based on Advanced Roadmaps "Parent Link" ?
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Jeff JEAN
It would be best if you create a separate question for this and mention my name in it as your requirement requires a lot of modifications.
Thank you and Kind regards,
Ram
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.