I'm trying to display a custom number field and required only on two combinations, otherwise the intent is to hide a custom number field on a specific issue type using Behaviors in ScriptRunner but no luck to get this to work. The two combinations are cascading select option values (parent - Test Support and child - Prod Environment) along with a singleselectField (Admin, Admin and Developer, EndUser and null).
Please review my code for this requirement effort and kindly suggest on the code change as needed to get this to work. This code seems to fail mainly due to Cascading select field validation and for the sake of testing, when I removed the code with reference to Cascading select field then it works fine. Your quick turnaround with code suggestions will be of great help.
def cascadecustomField = getFieldByName("What do you want to select?")
def selectedOptions = cascadecustomField.getValue() as Map
def parentOptionLevel = null
def childOptionLevel = '1'
def ParentOption = selectedOptions.get(parentOptionLevel).toString()
def ChildParentOption = selectedOptions.get(childOptionLevel).toString()
def numberField = getFieldByName("ID Number")
def singleselectField = getFieldById(getFieldChanged())
def selectedOption = singleselectField.getValue() as String
if(ParentOption == "Test Support" && ChildParentOption == "Prod Environment"){
if(selectedOption == "Admin" || "Admin and Developer"){
numberField.setHidden(false)
numberField.setRequired(true)
}
if(selectedOption == null){
numberField.setHidden(true)
}
if(selectedOption == "EndUser"){
numberField.setHidden(false)
numberField.setRequired(false)
}
}
The getFieldByName() on cascading custom field returns an ArrayList.
Therefore, to access the cascading custom field values in Behaviour, you can just use:
def parentOption = getFieldById(getFieldChanged()).getValue()[0]
def childParentOption = getFieldById(getFieldChanged()).getValue()[1]
I hope this helps!
Lost myself in another world of Atlassian work and now back onto this again, sorry to respond this late @Max Lim _Adaptavist_ and unfortunately that did not worked. I revised my code and it is kind of working but only after updating the ticket and what I was expecting is to work instantly prior to update.
Do I need to tweak any in the following revised code to make this to work as expected dynamically or on the fly?
def cascField = getFieldByName("Please select a category")
def hiddenField = getFieldByName("Text field")
def value = cascField.getValue() as List
def cfSelect = getFieldByName("Single select field")
def selectedOption = cfSelect.getValue() as String
if (value.size() == 2 && value.get(1) == "cascfieldValue" && selectedOption == "option1") {
hiddenField.setHidden(true)
}
else
hiddenField.setHidden(false)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Any inputs or thoughts on how to perform the above code validation specifically for the cascading select field please?
getFieldById(getFieldChanged()) doesn't seems like working in my code with reference to show/hide field...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
We use Dynamic forms Cascade select custom field and Behaviors are not currently compatible with Dynamic Forms. Product support adaptavist confirmed having an existing improvement ticket here: SRJIRA-3401. Resting this post finally!
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.