Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,457,219
Community Members
 
Community Events
176
Community Groups

Script Runner - Listener

Edited

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 Leader Oct 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
TAGS

Atlassian Community Events