You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
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
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
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.