Version
Jira v8.4.2, Scriptrunner 6.0.2-p5
Scenario
When a custom field drop down menu changes I need to trigger a script that show/hide another drop down menu based on the value of the first one. The code needed to do this can be seen in my question from yesterday
Problem
I have not understood how I can trigger the script when the parent field changes. I have not been able to see that I can capture this in my "Behaviour". If I am not missing anything out by what is shown in this video made by Adaptavist the server side script should be triggered simply by just changing the value of the drop down menu, no need to select "Create" or "Update". The video shows help text showing at once and also tabs being hidden/visible on the fly.
Do I need to configure Scriptrunner in any way to support server side script being triggered just by field update?
Let's see if I can walk you through the steps.
First, make sure you have a behaviour configuration with the correct project/issue type mapping.
Then go into the field section of the behavior.
Select the "parent' field from the drop-down at the bottom in the add field selection.
Then in the section for that parent field, add a server-side script.
The server-side script will execute when the form is loaded and every time the value is changed in that field.
The script can be much simpler than what you linked to (which seems to be more an event listener script than a behavior script).
Here is a sample script that you can adapt:
def optionsForVisible = ['option1']
def fieldToShowOrHide = 'name of field to show/hide'
def triggerField = getFieldById(getFieldChanged())
def triggerValue = triggerField.value
def targetField = getFieldByName(fieldToShowOrHide )
targetField.setHidden(!(triggerValue in optionsForVisible)).setRequired(!targetField.isHidden())
Thanks!
I have in the meantime learned that what I wanted in the first place was not a drop down menu (Single Select) but a Cascading Drop Down selection. But I still need to make the second drop down mandatory if values, so the script is needed.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@PD Sheehan , can I hide a custom field in the subtask based on a single select value of a field in the parent task? I am trying to do this using behaviors, but I am unable to figure out how to get the parent value on the code.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, there is a hidden field available to the behaviour script when you create a sub-task.
You can find that by starting a sub-task creation screen and examining the network traffic from your browser's developer panel.
There you will see a field sent to scriptrunner called parentIssueId.
From that, you get derive an issue object and fetch the value from the custom field.
For example:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.Option
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def parentIssueFld = getFieldById('parentIssueId')
if(!parentIssueFld) return //this is a not a sub task creation
def parentIssueId= parentIssueFld.value as Long
def parentIssue = ComponentAccessor.issueManager.getIssueObject(parentIssueId)
def selectCf = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName('Name of select field')[0]
def parentSelectValue = parentIssue.getCustomFieldValue(selectCf) as Option
def shouldBeHidden = parentSelectValue.value == 'Value that hides another field'
def otherField = getFieldByName('Other field name')
otherField.hidden = shouldBeHidden
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.
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.