I am new to Script Editor. I added the script, but doesn't look like it is working.
I added new behavior, added the field(radio button) and added Service side script. My environment is JIRA server. Any help is much appreciated. I am missing any configuration setting for the 1st time use?
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.priority.Priority
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def CauseCodeField = getFieldByName("TEST SK DropDown Field")
def CurrentField = getFieldById(getFieldChanged())
def selectedOption = CurrentField.getValue() as String
def isYesSelected = selectedOption == "Yes"
CauseCodeField.setRequired(isYesSelected)
I recently encountered such situation. when we add behaviour for checkbox/radio button or select list types it works with selected value ID instead of name(not sure the situation is same for you too)
if so you can modify your script as below
def required= getFieldById(getFieldChanged()).formValue as String == "12345"
//here 12345 is ID of the value "Yes". you can get this ID in URL tab by editing the value in field context
def CauseCodeField = getFieldByName("TEST SK DropDown Field").setRequired(required)
BR,
Leo
Thanks Leo. I tried this as well. But not seems to be working.
Something else blocking it not to work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your scripts look valid, try to print the log to check it:
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.priority.Priority
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def CauseCodeField = getFieldByName("TEST SK DropDown Field")
def CurrentField = getFieldById(getFieldChanged())
def selectedOption = CurrentField.getValue() as String
def isYesSelected = selectedOption == "Yes"
log.warn "CurrentField: " + CurrentField
log.warn "selectedOption: " + selectedOption
log.warn "isYesSelected: " + isYesSelected
CauseCodeField.setRequired(isYesSelected)
Check your atlassian-jira.log if the value is true. You can read more here how to get the log file. https://confluence.atlassian.com/adminjiraserver/logging-and-profiling-938847671.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you. Let me check the log.
Since its the Radio button, the behavior is expected to work when the value in the field is changed I assume.
Since this is new installation of Plug-in, is there any 1st time settings needs to be done so this works for my project and in my environment?
Thanks in advance for your help and time.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Since its the Radio button, the behavior is expected to work when the value in the field is changed I assume.
By default the radio button's value is None. Make sense why you need to change the radio button field value to "Yes" to make it required.
What is your requirement?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, When the value "Yes" is selected, I like to have next field ( dorp down type field) as mandatory. Default value for the drow down field is 'none'.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Also, appreciate if you can let me know how do I search the log file.
Could not see any data logged in the log file. When I search, I could not see it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is the script that I use and tested, you can change is a per your requirement:
/**
* Set custom field hidden/required
*/
def changedCF = getFieldById(getFieldChanged()) // Radio button A
def custField1 = getFieldById("customfield_10115") // num1 field
def changedCFValue = changedCF.getValue() as String
//Check if not null and equal to "No"
if (changedCFValue && changedCFValue.equalsIgnoreCase("No")) {
//Set hidden, not required, and null value, if value equal to "No"
custField1.setHidden(true)
custField1.setRequired(false)
custField1.setFormValue(null)
//Other than "No"
} else {
//Set not hidden, required, if value not equal to "No"
custField1.setHidden(false)
custField1.setRequired(true)
}
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.