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,299,390
Community Members
 
Community Events
165
Community Groups

Scriptrunner Behaviour to edit a custom field IF the field has certain value during transition

Hi Team,

 

I'm trying to put together a behaviour in scriptrunner where during transition (RFP to Implementing) user required to change a custom field IF this field has certain value (Unknown, Backlog, Test A), lam pretty new to coding, any idea is appreciated.

 

Field Name: Planned Version

Field type: Version Picker (multiple version)

Condition: ask to update field if the field has the value (Unknown, Backlog, Test A)

 

import com.atlassian.jira.component.ComponentAccessor

def sourceStatusId = jiraHelper.getStatusByName("RFP").iddef targetStatusId = jiraHelper.getStatusByName("IImplementing").id
def PlannedVersionField = = getFieldById("customfield_10000")

if (issue.status.id = "targetStatusId") {
if (getFieldById.value == "Unknown" || "Backlog" || "Test A") {
ASK user to update the field "Planned Version"
}
}
 

 

2 answers

0 votes

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

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.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

An update on Confluence Cloud customer feedback – June 2022

Hi everyone, We’re always looking at how to improve Confluence and customer feedback plays an important role in making sure we're investing in the areas that will bring the most value to the most c...

276 views 2 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you