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

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

Valiantys Support May 6, 2022

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

Suggest an answer

Log in or Sign up to answer
0 votes
Peter-Dave 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 Leaders.
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 Leaders.
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