Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
  • Community
  • Q&A
  • Jira
  • Questions
  • when epic link on a child ticket is changed it should automatically update the custom field to match

when epic link on a child ticket is changed it should automatically update the custom field to match

dileep
April 11, 2022

1)epic link in child ticket is changed it should automatically update the custom field to match the new epic 
2) whan an epic link is removed from the child ticket the custom field value is cleard?
custom field = GSIRT project field 

by using script runner listener 

thanks 

dileep

2 answers

1 accepted

1 vote
Answer accepted
Craig Nodwell
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
April 11, 2022

Some great examples in the Scriptrunner Library to get you started.
Scriptrunner Library: update-the-value-of-a-custom-field-using-a-listener 


System Events in Jira

Shout out if you hit a brick wall.

Craig Nodwell
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
April 11, 2022
Like dileep likes this
dileep
April 12, 2022

@Craig Nodwell  Thanks for response but I am completely new to scripting can you please  share script related to my requirements.

thanks 
dileep

0 votes
dileep
April 22, 2022
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 GSIRTProject = customFieldManager.getCustomFieldObjectsByName('GSIRT Project').first()
def epicLink = customFieldManager.getCustomFieldObjectsByName('Epic Link').first()
def projectGroupValue = issue.getCustomFieldValue(GSIRTProject)

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(GSIRTProject, 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(GSIRTProject, it.sourceObject.getCustomFieldValue(GSIRTProject) )
       issueManager.updateIssue(loggedInUser, issue, EventDispatchOption.DO_NOT_DISPATCH,false)
    }
} else if(issue.getCustomFieldValue(epicLink)==null) {
    issue.setCustomFieldValue(GSIRTProject, null)
    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(GSIRTProject, it.parentObject.getCustomFieldValue(GSIRTProject))
    issueManager.updateIssue(loggedInUser, subTask, EventDispatchOption.DO_NOT_DISPATCH,false)
}

Suggest an answer

Log in or Sign up to answer