Hi,
I just recently downloaded scriptrunner for a variety of purposes. While searching online I came across Use the behaviour functionality of the script runner to show/hide fields - iDalko used for showing/hiding a field based on a selection. I adapted it to the fields I'm trying to interact with, and it functions.
This doesn't quite work as expected, I was looking for a way to live update the fields, so that in the initial issue creation screen, if they pick option 'b' from the first dropdown, a second dropdown appears.
The way it's currently set up, even if I change the value in the first dropdown, I have to submit the issue and then go back in and edit it to see the second field.
What am I missing here? I'm rather new to coding and I think this can be done
Hi @Jordan Hauser welcome on the community. yeah, it is doable. Can you share the script and configuration you use right now?
def dropDown = getFieldById("customfield_10500") def conditionA = getFieldById("customfield_10501") log.debug("dropdown value" + dropDown.getValue()) if (dropDown.getValue() == "a") { conditionA.setHidden(false); } else { conditionA.setHidden(true); }
We are running Jira 8.15 Server. The above script is what I was trying earlier, the same as from the link I provided, minus 'conditionB' and the associated things.
I'm just not sure what I'm missing to look things up.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You also need to configure behaviours propertly, what does your configuration look like?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The mapping is to the project board I am testing on, right now its looking at all issue types.
The workflow guide is referencing the issuetype in the project I am testing on.
I don't have an initialiser set up yet.
I added the field that is the parent in the 'Fields' section, and both the parent/child fields are in the server side script area.
Not sure what else you're referencing for configuring behaviors
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, simply... you need to configure field which is changed (id=10500) to run the script. THen you can use:
log.error("executing behaviours")
def dropDown = getFieldById(getFieldChanged())
log.error("drop down")
def conditionA = getFieldById("customfield_10501") log.error("condition A")
log.error("dropdown value" + dropDown.getValue()) if (dropDown.getValue() == "a") { conditionA.setHidden(false); } else { conditionA.setHidden(true); }
I also suggest you to add some logging and check Jira log files so you will know whether the script is executed or not (I added it to the script example)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When you say 'configure field which is changed' do you just mean add it into the fields section? Or do you mean create an initialiser to say 'run this code whenever this field is changed'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Wow that works just like a charm, thank you so much for the assistance
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.
It helped me plenty, I did a little extra configuration, but that was exactly what I needed to get started, thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Cool, thank you for your feedback :)... So, would you be so kind and accept the answer?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi all
Anyone know how I can just get a script that will create a text box when I select "Other" from my dropdown list?
Really need help here?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Do you have the scriptrunner plugin, is it a server instance or a cloud instance
If you have scriptrunner, you will be needing the 'behaviours' interface the plugin provides
-Jordan
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.
Ok you have to create another field, as far as I understand it has to be a field.
You need to create a 'behaviour' in that section of scriptrunner. In that behaviour you need to map that behaviour to your project/workflow combination at the top.
Below the 'initialiser' section is where you can do things with specific fields. Add the field with the options in there.
At the bottom of that newly added field there should be some blue text 'add server side script'. Click it and it will bring up the script text entry box. I'm assuming you haven't done anything with the script editor, you can also write the code in there and reference the file in this spot.
In that server side script section for that field, input this code:
def dropDown = getFieldById(getFieldChanged()) //<---- the select field
def SOW = getFieldById("customfield_10202") //<---- the one to show/hide
//^^^^^^^ CHANGE THIS TO THE NEW FIELD ID
if (dropDown.getValue() == "OTHER (ENTER IN LINE BELOW)") {
//^^^^^ THE EXACT WAY YOU TYPED THE OPTION
SOW.setHidden(false);
} else {
SOW.setHidden(true);
}
-Jordan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jordan
First of all thanks for this help. can't thank you enough. I did try and this is my code that I have entered am I missing something?
Thanks
Kevin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kevin,
So it looks like you created a field that has the id of "customfield_15000", I can't check the field itself on your instance but it is indeed in the correct format.
The options for the select field have to have this exact thing in it- OTHER (ENTER IN LINE BELOW)
If you have the option in customfield_15000 as "Other (Enter in line below)" then it would fail, the option needs to be an exact string match.
-Jordan
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.