Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Script Runner - Listener

Prabakaran P July 13, 2022

Hi

I'm using the below Listener script to inherit the Epic custom field "Business clinetPO" values to the child ticket. I want set some conditions here that,

  • If the Epic "Business clinetPO" is set to one of the following values, don't propagate the value down to the child issues/sub-tasks:
    • Prospect
    • Unknown

Thanks,
Prabhu

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 BusinessClientPO = customFieldManager.getCustomFieldObjectsByName('Business ClientPO').first()
def epicLink = customFieldManager.getCustomFieldObjectsByName('Epic Link').first()
def BusinessClientPOValue = issue.getCustomFieldValue(BusinessClientPO)

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(BusinessClientPO, BusinessClientPOValue)
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(BusinessClientPO, it.sourceObject.getCustomFieldValue(BusinessClientPO) ) 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(BusinessClientPO, it.parentObject.getCustomFieldValue(BusinessClientPO)) issueManager.updateIssue(loggedInUser, subTask, EventDispatchOption.DO_NOT_DISPATCH,false) }

 

1 answer

0 votes
Antoine Berry
Community Champion
October 24, 2022

Hello @Prabakaran P ,

assuming your script works, you would just need to add a if clause to check if the value is select (also assuming your field is a single select list) : 

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 BusinessClientPO = customFieldManager.getCustomFieldObjectsByName('Business ClientPO').first()
def epicLink = customFieldManager.getCustomFieldObjectsByName('Epic Link').first()
def BusinessClientPOValue = issue.getCustomFieldValue(BusinessClientPO)

def subTasks = [] as ArrayList<Issue>

if (BusinessClientPOValue.getValue() in ["Prospect","Unknown"]) {
if (

if (issue.issueType.name == 'Epic' && issue) {
def links = issueLinkManager.getOutwardLinks(issue.id)
links.each {
def destinationIssue = it.destinationObject as MutableIssue
destinationIssue.setCustomFieldValue(BusinessClientPO, BusinessClientPOValue)
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(BusinessClientPO, it.sourceObject.getCustomFieldValue(BusinessClientPO) ) 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(BusinessClientPO, it.parentObject.getCustomFieldValue(BusinessClientPO)) issueManager.updateIssue(loggedInUser, subTask, EventDispatchOption.DO_NOT_DISPATCH,false) }
}

Suggest an answer

Log in or Sign up to answer