this script will not work and I can't think of another thing to try:. Basically, there are 2 fields in play (Priority and Business Justification).. If Priority is set to P1, I want the multi-line text field called Business Justification to be required. I have gotten very similar scripts to work in the past but this one for some reason is driving me crazy... when I do select P1, nothing happens to the Business Justification field)... very frustrating...likely a simple thing but I would appreciate the help.
def formField = getFieldByName("Priority")
def descField = getFieldByName("Business Justification")
def priority1 = formField.getValue()
if (priority1.getValue() == "P1") {
descField.setRequired(true)
}
else {
descField.setRequired(false)
}
Hi @Ed Richard ,
Can you try the below?
I don't access to a Server environment so not sure it will work, but it should help you to achieve what you are looking for:
By the way, I prefer to use Ids instead of names in case someone decides to change the name. The id will always remain the same while the name can change.
def prio= getFieldById("customfield_XXXXX")
def businessJustification= getFieldById("customfield_XXXXX")
def selectedOption = businessJustification.getValue() as String
if (selectedOption .getValue() == "P1") {
businessJustification.setRequired(true)
}
else {
businessJustification.setRequired(false)
}
thanks for reply....using server version.. tried above but not working.. it did give me some other things to try though... playing with it and experimenting while checking other related posts... nothing yet.. curious if it has to do with the fact that Priority field is a Jira system field and not a custom field??
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.
not even this worked:
def prio = getFieldByName("Priority")
def selectedPriority = prio.getValue()
def BusinessJustification= getFieldById("customfield_13900")
if (selectedPriority == "P1") {
BusinessJustification.setRequired(true)
}
else {
BusinessJustification.setRequired(false)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Any errors?
You may need the libraries to access, https://library.adaptavist.com/entity/set-behaviour-hidden
import com.atlassian.jira.issue.IssueFieldConstants
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
Also try easy from the beginning like to test the Prio value only as it seems to fail there
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I agree on where its failing...I don't see any errors (do I go somewhere to see them or a log of some type?) I did move the setting of the Business Justification outside of the if statement temporarily to verify I can make that field required (which works so there is no problem there)... its all about getting the value from Priority now it seems
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Through much experimentation and community searching, I got it.. please don't as how.. after 12 hours of trying Im just going to take it and use it for now...thanks for the help... it ended up being this:
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueConstantImpl
def prio = getFieldById(getFieldChanged())
def selectedPriority = ((IssueConstantImpl) prio.getValue()).getName()
def BusinessJustification = getFieldById("customfield_13900")
if (selectedPriority == "P1") {
BusinessJustification.setRequired(true)
}
else {
BusinessJustification.setRequired(false)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Ed Richard thanks so much, I had the same prob, and the only difference I have with you is the definition of "selectedPriority" that I missed.
GREAT HELP.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.