Hello,
I want a date field to only be visible when another field (Date and Time occurrence) is filled in.
I would like to implement this behavior with the script runner.
Thankful if you can help me.
Thanks.
@Patricia Vale -
Hi Patricia:
Here are the steps and the "server side script" for you to try
1) Create a Behavior setup for your target project and specific issue type or request type
2) In the setup, select the field (the field that is filled or not)
3) Add the server side script to something like below
def issueXField = getFieldById("customfield_xxxxx") // your date fielddef issueYField = getFieldById("customfield_xxxxx") // your field you want to hide/displayString issueXValue = issueXField.getValue()if (!issueXValue){ // if the date field is not empty issueYField.setHidden(false)} else { issueYField.setHidden(true) }
Hope this helps. If it does, please remember to click the "Accept answer" button, so others with similar asks will see this posting as an answered entry.
Best, Joseph Chung Yin
Jira/JSM Functional Lead, Global Technology Applications Team
Viasat Inc.
Hi @Patricia Vale
Your requirement is pretty straightforward.
You will need to create a Server-Side Behaviour for the first Date field, i.e. when the value is set in this field, the second Date field will be hidden.
When initialising the field the Server-Side Behaviour is configured for, you must declare the field using this structure:-
def field = getFieldById(fieldChanged)
Otherwise, the Behaviour will not work as expected.
Below is a sample working code for your reference:-
import com.onresolve.jira.groovy.user.FieldBehavioursimport groovy.transform.BaseScript@BaseScript FieldBehaviours behavioursdef date1 = getFieldById(fieldChanged)def date1Value = date1.valuedef date2 = getFieldByName('Date 2')date2.hidden = falseif (date1Value) { date2.hidden = true}
Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.
Below is a screenshot of the Server-Side Behaviour configuration:-
Below are a couple of test screenshots for your reference:-
1) When the create screen is first opened, both the date fields are visible as no modification has been set to the first Date field as shown in the screenshot below:-
2) Next, add a value to the first date field as shown in the screenshot below:-
3) As expected, once the value is set in the first date field, the second date field is hidden, as shown in the screenshot below:-
I hope this helps to solve your question. :-)Thank you and Kind regards,
Ram
Hi @Joseph Chung Yin ,
Thank you for your quick response and help.
I tried, but it didn't work.
Currently we are in Data Center and not Server. Could that be why?
Thanks
No, it should not matter. Please provide more details on your Behavior configuration setup details...
Lastly what is your DC version and ScriptRunner for Jira version?
Best, Joseph
@Joseph Chung Yin - I am wondering if you can help me out. I have a Behavior setup to work properly on the Create and Edit form, but the field still shows up on the IssueView. The behavior shows one field if the content of another field is a certain value. I saw a video for Jira Cloud where there is a setting to choose which views to use the behavior on, but I do not see that option in Jira DC (Version 8.3.4.0). Is there a way to set that in the script itself?
@Sheila S_
Welcome to the community. In your ScriptRunner for Jira add-on installation, can you confirm that you also see the Behavior component call out.
It looks like you're new here. Sign in or register to get started.