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,559,041
Community Members
 
Community Events
184
Community Groups

Looking for ScriptRunner example on changing an issue status

Hey Community...  I'm new to scriptrunner and I'm attempting to do the following... 

on issue creation of a specific type of issue (this part is handled in the listener) 

I want to add a label (which that part seems to work) 

set the Epic link to a specific epic (that part does not work)

set the issue status to a status that is not the default (that part does not work)

and extra bonus would be is logging actually worked so that I can debug stuff myself. 

 

here is what I got so far... what should I do to make this better? (oh and also work as expected) 

I am a novice with groovy 

import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.label.LabelManager
import com.atlassian.jira.issue.label.Label
import org.apache.log4j.Logger
import org.apache.log4j.Category

def Category log = Category.getInstance("com.onresolve.jira.groovy")
log.setLevel(org.apache.log4j.Level.ALL)

def user = ComponentAccessor.jiraAuthenticationContext?.getLoggedInUser()

def labelManager = ComponentAccessor.getComponent(LabelManager)

labelManager.addLabel(user,issue.id, "support-product", false)
log.debug("label added")

def issueManager = ComponentAccessor.getIssueManager()
def epicIssue = issueManager.getIssueObject("SCMNEW-7") // Support requests epic
def epicLink = customFieldManager.getCustomFieldObjectByName('Epic Link')
issue.setCustomFieldValue(epicLink, epicIssue)
issue.setStatusId('22')
log.debug("Set the status")

log.debug("set epic link")

UserMessageUtil.success("Created issue for SCM.")

 

1 answer

got it working.. BUT I'm willing to learn if someone wants to improve or if I make mistakes

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.label.LabelManager
import com.atlassian.jira.issue.label.Label
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.bc.issue.IssueService

def user = ComponentAccessor.jiraAuthenticationContext?.getLoggedInUser()
def labelManager = ComponentAccessor.getComponent(LabelManager)
def issueManager = ComponentAccessor.getIssueManager()
def issue = issueManager.getIssueObject(event.issue.key)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def epicIssue = issueManager.getIssueObject("SCMNEW-7") // Support requests epic
def epicLink = customFieldManager.getCustomFieldObjectByName('Epic Link')
IssueService issueService = ComponentAccessor.getIssueService()
def actionId = 51 // change this to the step that you want the issues to be transitioned to
def transitionValidationResult
def transitionResult

// set the Label
labelManager.addLabel(user,issue.id, "support-product", false)
// set the Epic Link
issue.setCustomFieldValue(epicLink, epicIssue)
issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, true)

// transition the issue to new status

log.debug("The issue type is: " + issue.getIssueType().name)

transitionValidationResult = issueService.validateTransition(user, issue.id, actionId,new IssueInputParametersImpl())

if (transitionValidationResult.isValid()) {
transitionResult = issueService.transition(currentUser, transitionValidationResult)
if (transitionResult.isValid())
{ log.debug("Transitioned issue $issue through action $actionId") }
else
{ log.debug("Transition result is not valid") }
}
else {
log.debug("The transitionValidation is not valid")
}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events