The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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?
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
Hi Marco,
If we are talking about a transition validator, the script should be something like this:
import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.InvalidInputException
def cfMgr = ComponentAccessor.getCustomFieldManager()
def companyAndRole = issue.getCustomFieldValue(cfMgr.getCustomFieldObjectByName("Company and Role"))
def applicationArea = issue.getCustomFieldValue(cfMgr.getCustomFieldObjectByName("Application Area"))
if(!companyAndRole && applicationArea.getValue().equals("SL SAP ECC")){
throw new InvalidInputException("Company and Role field is required!")
}
return true
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello everyone, Hope everyone is safe! A few months ago we posted an article sharing all the new articles and documentation that we, the AMER Jira Service Management team created. As mentioned ...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.