I am using Jira Software 8.4.3 and ScriptRunner 5.6.7.1-jira8
Using Behaviors, I have a custom field which is a dropdown list and when the value "Yes" is selected, I expect to see 2 other custom fields to change to "required". When I switch back to a value of "No" I expect to see the other 2 fields NOT required and hidden or read only. I have found forum posts online to do all of this, but I am not seeing any real time changes when the dropdown values are changing, which was behavior seen in tutorial videos.
If I update the JIRA issue and re-open that issue, only then do I see that the other two fields have become required.
I believe this question is also asking about seeing this "dynamic" changing of required/not required on the fly:
At the bottom of this the person asking the question has put the following code:
if ((getFieldById(getFieldChanged()).value as Priority)?.name == "High") { ... }
I think this is what I am looking for but as I have a custom field I am not sure how to modify this to make it work for my needs.
What I have coded so far is the following:
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;
def costImpField = getCustomFieldManager().getCustomFieldObject("customfield_10400");
def costImpValue = (String)underlyingIssue?.getCustomFieldValue(costImpField);
def sbirsProgImpField = getFieldById("customfield_10619")
def govtImpField = getFieldById("customfield_10620")
if (costImpValue.equals("Yes")) {
sbirsProgImpField.setRequired(true)
//sbirsProgImpField.setHidden(false)
//sbirsProgImpField.setReadOnly(false)
govtImpField.setRequired(true)
//govtImpField.setReadOnly(false)
//govtImpField.setHidden(false)
} else {
sbirsProgImpField.setRequired(false)
//sbirsProgImpField.setHidden(true)
//sbirsProgImpField.setReadOnly(true)
govtImpField.setRequired(false)
//govtImpField.setHidden(true)
//govtImpField.setReadOnly(true)
}
Hi @Justin G
The behaviour should be attached to the field to which you want to list for changes.
getFieldChanged()
always returns the field ID of the field the behaviour fires for. You can find more information with example in this Link.
def formField = getFieldById(getFieldChanged())
def sbirsProgImpField = getFieldById("customfield_10619")
def govtImpField = getFieldById("customfield_10620")
def selectedOption = formField.getValue() as String
if (selectedOption == "Yes") {
do something
}
else {
do something
}
Hope this helps!
Thank you, that worked, I was accessing the fields incorrectly and this was much simpler than I had coded it to be. I had the behavior on the correct field but accessing the values was wrong. thanks much
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Should this work if the value is edited back between yes and no? or is it a once only?
Trying to have something similar on a transition screen.
The field is already populated, but if it changes, the respective field visibility and requirements should change accordingly.
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.