You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hi all! Trying to write a script in Adaptavist ScriptRunner to update the Initiative (advanced roadmaps fields) when all epics under it are "Closed". I created a scripted field for the Initiative-Epic Relationship called "Initiative-Epic Link". I borrowed some of the code from this article and tinkered around with it for quite a while but cannot seem to get it working. Has anyone successfully got this working or is any experienced in this type of thing? I'm still a novice at writing scripts. Thanks in advanced!
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.workflow.TransitionOptions
def issueManager = ComponentAccessor.issueManager
def issue = issueManager.getIssueObject("DEMO-130") //issue key
log.warn "issue: "+issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def epicInitLink = customFieldManager.getCustomFieldObjectByName("Initiative-Epic Link")
def cfFieldValue = issue.getCustomFieldValue(epicInitLink)
def parentIssue = issueManager.getIssueObject(cfFieldValue.toString()) //get parent issue object
// To shows cfFieldValue has value
log.warn "Initiative-Epic Link value: "+cfFieldValue
// the name of the action you want to move the issue to
final String actionName = "Closed"
// the name of the issue link
final String issueLinkName = "Initiative-Epic Link"
def workflow = ComponentAccessor.workflowManager.getWorkflow(issue)
def actionId = workflow.allActions.findByName(actionName)?.id
def issueLinkManager = ComponentAccessor.issueLinkManager
// Find all the linked - with the "Initiative-Epic Link" link - issues that their status is not completed
def linkedIssues = issueLinkManager
.getOutwardLinks(parentIssue.id)
.findAll { it.issueLinkType.name == issueLinkName }
*.destinationObject?.findAll { it.status.statusCategory.name != "Complete" }
// If there are still open linked issues (except the one in transition) - then do nothing
if (linkedIssues - issue) {
log.warn "Not all Epics are Closed"
}
def issueService = ComponentAccessor.issueService
def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.setComment("This Initiative closed automatically because all the Epics in this Initiative are closed.")
issueInputParameters.setSkipScreenCheck(true)
def transitionOptions = new TransitionOptions.Builder()
.skipConditions()
.skipPermissions()
.skipValidators()
.build()
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def transitionValidationResult = issueService.validateTransition(loggedInUser, parentIssue.id, actionId, issueInputParameters, transitionOptions)
assert transitionValidationResult.isValid() : transitionValidationResult.errorCollection
def result = issueService.transition(loggedInUser, transitionValidationResult)
assert result.isValid() : result.errorCollection