Forums

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

Looking for ScriptRunner example on changing an issue status

John VanRyn
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 1, 2020

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.")

 

2 answers

Suggest an answer

Log in or Sign up to answer
0 votes
PD Sheehan
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.
May 7, 2022

Here is how I would do it

def plannedVersionField = = getFieldById("customfield_10000")
plannedVersionField.clearError()

def goingToImplementing = destinationStepName == 'Implementing'
def comingFromRFM = underlyingIssue?.status.name == 'RFP

def valuesThatRequireChange = ['Unknown', 'Backlog', 'Test A']

if(comingFromRFM && goingToImplementing){
if(plannedVersionField.value in valuesThatRequireChange){
plannedVersionField.setError("Please update. ${valuesThatRequireChange.join(',')} are not allowed when movig from RFP to Implementing")
}
}
0 votes
Andrea Pannitti
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.
May 6, 2022

Hi,

to do this, you could add a Simple scripted validator on the transition with this Condition:

!["Unknown", "Backlog", "Test A"].contains(cfValues['Your Custom Field'])

and setting the Error Message with a message like the following:

Please, update the field: Planned Version

And selecting the Field: Planned Version.

TAGS
AUG Leaders

Atlassian Community Events