Hi everyone,
Using the behaviours initializer on Scriptrunner, I am trying to display certain fields only when a user clicks on a certain check box. I am not sure how exactly to start the groovy script and I am wondering if anybody has seen something similar or has done something similar that they are willing to share.
Example: User clicks on single day check box and then full day and half day check boxes display along with a date picker.
Hello,
You should be able to use something similar to what is shown in this example in the docs.
Let me know if you need help getting it set up.
Jenna
Thanks for the reply Jenna. The field doesn't change when the custom field either gets chosen or clicked. I also used another field besides a checkbox to see if that would work. Some pictures and code can be seen below:
import com.onresolve.jira.groovy.user.FieldBehaviours import com.onresolve.jira.groovy.user.FormField import com.atlassian.jira.component.ComponentAccessor FormField ParentField = getFieldById(getFieldChanged()) FormField ChildField1 = getFieldByName ("Day Duration") String ParentFieldVal = (String) ParentField.getValue() if (ParentFieldVal == ("Single Day")) { ChildField1.setHidden(false) ChildField1.setRequired(true) } else { ChildField1.setHidden(true) ChildField1.setRequired(false) }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
You should make an initializer function containing this:
def hiddenField = getFieldByName("the field you want initially hidden") hiddenField.setHidden(true)
And a behavior function that acts on the check box field containing something similar to this:
def hiddenField = getFieldByName("the initially hidden field") def checkBox = getFieldById(getFieldChanged()) def selectedOption = checkBox.getValue() as String def isOtherSelected = selectedOption == "the checked option(s) that makes your field appear" hiddenField.setHidden(!isOtherSelected) hiddenField.setRequired(isOtherSelected)
You may have to fiddle with with what selectionOption ends up equaling to make it true if you want to use more than one check box in order to make the field appear. I tested this using just one checkbox. This should get you started at least though.
Let me know if you have any more questions!
Jenna
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am sorry, I don't understand the differences between the initializer function and the behanviour function. I am new to working with Behaviour functions.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No problem!
You'll want to create all of this under a single 'Behavior'. However, you want to set up the first part under an initialiser function.
It will look something like this:
Click 'Create Initialiser' and insert the snippet I provided.
Then, the field behavior is set up by picking your field (the check box) out of this list:
You will then see something like this appear:
Click 'Add serverside script' here and add the next part of the code.
When you're done, the entire Behavior should look something like this:
Let me know if you need any more help!
Jenna
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Jenna, this has been really helpfull. I got it to work.
I have one more question, would this method be able to display a scripted field as a view only in the create window? (Kind of like a dynamic field)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Good! I'm glad I could help you out. :)
Scripted Fields don't show up in the create or update/edit screens.
By a 'dynamic field' do you mean that if you do something in one field the content changes in your read-only field? If so, that would probably be best achieved by another behavior. Just make sure you don't have mutiple behavior functions acting on one field. That can cause unpredictable behavior or make them simply not work.
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.