Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

ScriptRunner - Display/Hide and Require Field Input Conditionally

Ricky Wang Lin
Contributor
July 29, 2021

Hi there.  I have the following scenario where I wonder ScriptRunner's Behaviour feature can help with the following two fields:

  • Field 1: "Require Code?" - Checkbox
    • Option: Yes
  • Field 2: "Code Location" - Single-line text

Use case:

  • Upon ticket creation, hide "Code Location" by default
    • If "Require Code?" field is set to "Yes", display and require "Code Location" to be entered.

The documentation doesn't really seem to cover this particular scenario.  Anyone have any thoughts?

1 answer

1 accepted

1 vote
Answer accepted
Helmy Ibrahim _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 29, 2021

Hi Ricky,

I can confirm that this is possible with Behaviour.

Here is an example of your use case:

1 - Create a Behaviour and map to a project and issue type.

2 - Add a field 'Code Location' and toggle 'Shown' to make it 'Hidden'

Screenshot 2021-07-30 at 4.16.25 AM.png

3 - Add a field 'Require Code?' and add the following server-side script:

def requireCode = getFieldById(getFieldChanged())
def requireCodeValue = requireCode.getValue()

def codeLocation = getFieldByName("Code Location")

if ('Yes' in requireCodeValue) {
    codeLocation.setHidden(false)
    codeLocation.setRequired(true)
} else {
    codeLocation.setHidden(true)
    codeLocation.setRequired(false)
}

I hope the above helps! :)

Cheers,
Helmy

Ricky Wang Lin
Contributor
August 3, 2021

Hi Helmy.  Thank you so much.  I followed your steps to the tee and it works exactly as expected.

Thank you so much for the screenshots and detailed guidance!

Question:  Apart from the documentations, is there anywhere else I could look at to get better at using ScriptRunner?  Specifically, how to do some of the coding to satisfy some common use cases based on examples.

Helmy Ibrahim _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 3, 2021

Hi Ricky,

You're very welcome! I guess you can check out the Adaptavist Library and it is essentially a collection of scripts based on common use cases. And be sure to check the Tutorials section in the docs.

And of course, the Community! :) 

We also have a YouTube channel where we upload solutions to a specific use case from time to time. If you're new to the product and scripting, I'd recommend this webinar.

If I have helped you with my first answer, please accept it to raise its visibility.

Cheers,
Helmy

Marco Anjelski
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 24, 2023

Hi @Helmy Ibrahim _Adaptavist_ ,

How do I get this to work with a Select List (Cascading)? Only what is in the parent element (first dropdown) counts as a trigger. The content of the child elements should have no influence.

Thanks :) 

Helmy Ibrahim _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.
November 24, 2023

Hi @Marco Anjelski

Cascading field returns a list where the first element is the parent's value. So, you can do it like the below:

def cascadingField = getFieldById(getFieldChanged())
def fieldValue = cascadingField.getValue() as List

def parentValue = fieldValue[0] // Use [1] to get the child's value

if (parentValue == 'parent value here') {
    // do something
}
I hope this helps :)

Regards,
Helmy

Like Marco Anjelski likes this
Marco Anjelski
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 26, 2023

Hi @Helmy Ibrahim _Adaptavist_,

thank you so much. That helped a lot. Now everything is working as expected. :)

 

Best regards

Marco

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Atlassian Community Events