Forums

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

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
TAGS
atlassian, team '25 europe, atlassian event, barcelona 2025, jira, confluence, atlassian intelligence, rovo, ai-powered collaboration, developer tools, agile teams, digital transformation, teamwork solutions, atlassian conference, product announcements

🌆 Team '25 Europe registration is now open!

Join the largest European gathering of the Atlassian Community and reimagine what’s possible when great teams and transformative technology come together. Plus, grab your Super Fan ticket now and save over €1,000 on your pass before prices rise on 3 June.

Register now
AUG Leaders

Atlassian Community Events