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

Scriptrunner behaviour - set field mandatory if specifics values selected in priority system field

Celeste D'Alessandro August 11, 2020

Hi, 

I'm new in scriptrunner and i need help to create a behaviour to set a field mandatory if priority is "high". But the script does not work. 

 

import com.atlassian.jira.issue.priority.Priority

def priority = getFieldById("priority")
def justificacion = getFieldById("customfieldid_15801")

if (priority == "High") {
justificacion.setRequired(true)

}
else {
justificacion.setRequired(false)
}

Thansk!

 

Maybe something like this but whit priority

 

import com.atlassian.jira.issue.resolution.Resolution

def resolutionField = getFieldById("resolution")

def fixVersionsField = getFieldById("fixVersions")

def resolution = resolutionField.getValue() as Resolution

if (resolution.name == "Fixed") {

fixVersionsField.setRequired(true) fixVersionsField.setHidden(false) }

else {

fixVersionsField.setRequired(false) fixVersionsField.setHidden(true)

}

 

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
2 votes
Answer accepted
Jia Jie
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.
March 17, 2021

Hi @Celeste D_Alessandro ,

You'll need to get the Priority field value for the if-else condition. For example:

import com.atlassian.jira.issue.priority.Priority
import com.atlassian.jira.issue.IssueConstantImpl

def priority = getFieldById(getFieldChanged())
def selectedPriority = ((IssueConstantImpl) priority.getValue()).getName()

def justificacion = getFieldById("customfieldid_15801")

if (selectedPriority == "High") {
    justificacion.setRequired(true)

}else {
   justificacion.setRequired(false)
}
TAGS
AUG Leaders

Atlassian Community Events