Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Show/hide custom field using Behaviors from Adaptivist

Jeanne Howe
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 13, 2017

We are trying to view/hide a text field based on the value of the JIRA Flagged field. We have the following script set up:

def reasonForBlock = getFieldById("customfield_16560")
def flaggedField = getFieldById(getFieldChanged())

def selectedOption = flaggedField.getValue() as String
def isImpedimentSelected = selectedOption == "Impediment"

reasonForBlock.setHidden(! isImpedimentSelected)

 

We have applied this to the Flagged field (a checkbox field)

Expected results - the text field would remain hidden until the Flagged field was set

Actual results - the text field is not visable when the Flagged field is set

2 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Jonny Carter
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 13, 2017

So, I was able to hide a field using this behaviour just fine. A few thoughts:

  1. Be aware that behaviours only function on the create/edit screen, and to a lesser extent things like workflow screens and similar views. Hiding fields from the View Issue page isn't really what they do. There is technically a beta feature to do that, but it requires converting fields to a particular type, which can be a bit dodgy.
  2. Are you doing this in an initializer? It should be a behaviour script on the Flagged field itself.
    Flagged Field Behaviour.png
Jeanne Howe
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 14, 2017

Hi Jonny,

Thank you for the response.

I am not trying to hide the field on the view screen (if it's empty it will not display) I am looking at the create and edit screens.

I have the text field hidden initially, but my expectation was that, on the edit screen, once I checked the Flagged field, the text field would then be displayed. This is where I am having issues.

If I could figure out how to add an attachment, I could show you what I am seeing

 

Jeanne Howe
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 14, 2017

Flag_Unchecked.png

Jeanne Howe
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 14, 2017

Flag_Checked.png

Aidan Derossett _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 19, 2017

As Jonny mentioned before, you won't see the behavior that you are expecting if you have set up an initializer. An initializer should only run when the screen is first loaded and, therefore, a change to the form field won't be caught after its initial execution. 

So instead, you should set up a behavior that is mapped directly to the Flagged field. I'll attach a couple of screenshots to help. Screen Shot 2017-06-19 at 11.09.24 AM.pngScreen Shot 2017-06-19 at 11.09.39 AM.png

Jeanne Howe
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 19, 2017

Aidan,

Thank you for the clariofication, I missed this comment on Jonny's reply.

I will set up the script and test the behavior.

 

Jeanne

Jeanne Howe
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 23, 2017

Aidan,

I think I have this working. It took two beahviors:

1 -  A behavior on the Reason for Block field to hide the field initailly

2 - A server side script on the Flagged field looking for the "Impediment" value. If the value is found, the Reason for Block field is shown

Serverside script: 

 

def reasonForBlock = getFieldById("customfield_16560")
def flaggedField = getFieldById("customfield_10160")

def selectedOption = flaggedField.getValue() as String
log.debug "Selected option: $selectedOption"

if (selectedOption == "Impediment") {
reasonForBlock.setHidden(false)
}
else {
reasonForBlock.setHidden(true)
}

 

Does this look like the best way to handle this? Do you have any other recommendations?

 

Jeanne

Jeanne Howe
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 23, 2017

Further testing shows this is not working as I had hoped. JIRA will always display a field on the view screen if there is a value in the field.

If I click the FLagged field, then add a value to the Reason for Block field all is good. Both fields display on the view screen.

If I edit the issue and uncheck the Flagged field, the Reason for Block field still displays on the view screen because it still has a value. 

Is there anyway to hide the field even if there is a value in the field? Or can the field be cleared if the Flagged field is not set?

Aidan Derossett _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 26, 2017

Hey Jeanne,

I've tested this myself and I believe you can just set the Reason For Block field to 'null' as I do in your modified script below:

def reasonForBlock = getFieldById("customfield_16560")
def flaggedField = getFieldById("customfield_10160") def selectedOption = flaggedField.getValue() as String log.debug "Selected option: $selectedOption" if (selectedOption == "Impediment") { reasonForBlock.setHidden(false) } else { if(reasonForBlock.value) { reasonForBlock.setFormValue(null) } reasonForBlock.setHidden(true) }

Basically, any time the the flaggedField has a selectOption that is not equal to "Impediment" the reasonForBlock field will be cleared (if it has a value).

 

Jeanne Howe
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 17, 2017

Thank you Aidan!

This is exactly what I needed.

 

Jeanne

Aidan Derossett _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 19, 2017

No problem! 

If you have any other issues, let us know :)

Anna Protopapa August 11, 2017

Hello,

I want to try this example but I have a question: where I will paste this code?

Thank you

Aidan Derossett _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 22, 2017

Hey Anna!

All of the code posted above is meant to be used in a ScriptRunner Behaviour. If you follow our replies you should be able to track down which code is attached to what fields. :)

If you're not sure how to work with behaviours, you can check out our documentation here.

Jyoti Karwal April 19, 2018

Hi,

I have tried this example for Select list and it worked fine, only one issue has encounter that i am not able to create any issue.

I had set a script behaviour on create screen i am getting following issues:

1. When i click on the create button for issue and select the option from the list, my fields are not showing up.

2. But when i go to Project settings and from there i click on the Create button and select option from the list the fields are showing (that's a strange behaviour)

3. After adding all the values on the screen, and hit create button for creating issue at the bottom, the screen gets frozen and i am not able to create issues.

I can provide the screen shots, if anyone will help me with this issue.

Thanks,

Jyoti 

Sema YILDIRIM August 7, 2019

 I couldn't tell you what I wanted. I want the "options" options to come according to the selected "issues type".

 

Untitled.png

0 votes
Sema YILDIRIM August 7, 2019

Hi there is more than one "add context" in "select single". How do I make the corresponding "select list" according to my "numbers" I want?

TAGS
AUG Leaders

Atlassian Community Events