Heads up! On March 5, starting at 4:30 PM Central Time, our community will be undergoing scheduled maintenance for a few hours. During this time, you will find the site temporarily inaccessible. Thanks for your patience. Read more.

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

Behaviours - Required custom field

Isabel Fonseca
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.
July 25, 2023

Hellow,

In a project, when issue created, if "Application" value equals to "Cleva Life v7", the "Functional Area" required.

The "Application" and "Functional Area", are custom fields Type "Select List (single choice)".

Exemple:

1_Example.GIF

The problem, is that don't work very well.

 

Behaviour:

3.GIF 2.GIF

Script:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
import com.atlassian.jira.datetime.DateTimeFormatter
import com.atlassian.jira.issue.customfields.impl.DateTimeCFType
import com.atlassian.jira.issue.fields.CustomField
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.user.ApplicationUser
import org.apache.log4j.Logger
import org.apache.log4j.Level
import groovy.transform.BaseScript
import groovy.transform.Field

@BaseScript FieldBehaviours fieldBehaviours
@field ApplicationUser loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

// Set the log level
def log = Logger.getLogger(getClass())
log.setLevel(Level.DEBUG)


// Related issue field name
final functionalAreaName = "Functional Area"
final applicationName = "Application"

//Issue picker field and its value is obtained
def issuPickerFieldFunctionalArea = getFieldByName(functionalAreaName)
def issuePickerFieldValueFunctionalArea = issuPickerFieldFunctionalArea.value

def issuPickerFieldApplicationName = getFieldByName(applicationName)
def issuePickerFieldValueApplicationName = issuPickerFieldApplicationName.value

// Application value equals to "Cleva Life v7" , Functional Area required
if (issuePickerFieldValueApplicationName == "Cleva Life v7") {
issuPickerFieldFunctionalArea.setRequired(true)
return
} else {
issuPickerFieldFunctionalArea.setRequired(false)
return
}

 

What is wrong?

 

Thanks,

Isabel Fonseca

 

1 answer

1 accepted

0 votes
Answer accepted
Isabel Fonseca
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.
July 25, 2023

I found a better solution, insert a validator in transition of issue:

4.GIF

Many thanks,

Isabel Fonseca

Suggest an answer

Log in or Sign up to answer