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

Next challenges

Recent achievements

Recognition

  • Give kudos
  • My kudos

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

I want to make a field mandatory in the Create screen if another field has certain value

I want to make a field (Company and Role) mandatory in the Create screen if another field (Application Area)(select list) has the value "SL SAP ECC”.

 

I use a validator on transition Create.

 

import com.onresolve.jira.groovy.user.FieldBehaviours

import groovy.transform.BaseScript

 

@BaseScript FieldBehaviours fieldBehaviours

 

def ApplicationAreaField = getFieldById(getFieldChanged())

def CompanyandRoleField = getFieldByName("Company and Role")

 

String ApplicationAreaValue = ApplicationAreaField.getValue()

 

if (ApplicationAreaValue == 'SL SAP ECC') {

    CompanyandRoleField.setRequired(true)

} else {

    CompanyandRoleField.setRequired(false)

}

 

But JIRA gives the report about that field, regardless of which value is chosen in the select list.

 

Where do I make the mistake?

2 answers

1 accepted

0 votes
Answer accepted

Adaptavist told me the following:

 

To achieve what you are asking you need to use a behaviour instead of a validation.

Can you try this code as a server side script for a behaviour on the "Application Area" field:

 

def ApplicationAreaField = getFieldByName("Application Area")
def CompanyandRoleField = getFieldByName("Company and Role")

ArrayList ApplicationAreaValue = ApplicationAreaField.getValue() as ArrayList

if (ApplicationAreaValue.contains("SL SAP ECC")){ 
CompanyandRoleField.setRequired(true)
} else{ 
CompanyandRoleField.setRequired(false) 
}

 And this works for my situation

Do you use script behavior or script validator? According to your syntax, it seems like you are using behavior.

If you are using script validator, use this script:

Note that you need to change the id in applicationAreaValue and companyRoleFieldValue params.

import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.InvalidInputException

def customFieldManager = ComponentAccessor.getCustomFieldManager()

String applicationAreaValue = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject(11111 as long))//Change the id to 'Application Area' field id
String companyRoleFieldValue = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject(11111 as long))//Change the id to 'Company and Role' field id

if (applicationAreaValue == "SL SAP ECC") {
if (companyRoleFieldValue == null) {
invalidInputException = new InvalidInputException("'Company and Role' is mandatory when 'Application Area' is SL SAP ECC")
return null
}
}

Suggest an answer

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

Share your Confluence Cloud experience for a chance to win $500!

Take our 5-minute survey to win a $500 Visa gift card! Are you currently using Confluence Cloud? We want to hear from you! Fill out this quick survey about your Confluence Cloud experience so we ...

139 views 1 8
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