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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,467,417
Community Members
 
Community Events
177
Community Groups

ScriptRunner behaviour for hiding a field based on another fields value

Edited

Given the user is trying to create or edit an issue,

When the component (Component/s) is chosen as "Generic_Tasks"

Then the custom field "DoD" (customfield_14201) should be hidden.

 

This is the simple script I used but it doesn't seem to work:

 

def ComponentsField = getFieldById("Component/s")
def DoDField = getFieldById("customfield_14201")
def Componentvalue = ComponentsField.getValue()

if (Componentvalue == "Generic_Tasks") {

DoDField.setHidden(true)}

else {
DoDField.setHidden(false)
}

 

Any help here is highly appreciated.

Thanks in advance,

Venkat

1 answer

1 accepted

1 vote
Answer accepted
Vikrant Yadav Community Leader Jul 21, 2021

Hi @Venkat_S 

you'll have to place this script as server side script for Component/s field

import com.atlassian.jira.bc.project.component.ProjectComponent
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours

def plan_modification = getFieldById('customfield_39257') //replace with Dod field Id

def components = getFieldById(getFieldChanged()).getValue() as List<ProjectComponent>
def compField = getFieldById("component")
compField.setAllowInlineEdit(false)

if (components.any {it.name.contains("Generic_Tasks")}) {
plan_modification.setHidden(false)
plan_modification.setRequired(true)
}
else {
plan_modification.setHidden(true)
plan_modification.setRequired(false)
}

Hello @Vikrant Yadav ,

Thank you so much for the quick solution.

This one worked like a gem !

 

Thanks again !

Regards,

Venkat

Like Vikrant Yadav likes this
Vikrant Yadav Community Leader Jul 21, 2021

@Venkat_S  Cool, Glad to hear it works for you!

Hello @Vikrant Yadav 

In addition to this,

I also need help with another behaviour with the Xray "Test Repository path" field.

WHEN the "Test Repository Path" is "NTG7 Widgets"

THEN the custom fields "Review" and "Review Comments" should be made mandatory.

ntgsui_scriptrunner.png

 

Thanks in advance,

Venkat

Vikrant Yadav Community Leader Jul 21, 2021

Hi @Venkat_S  Is Test Repository path dropdown field ? 

I think this is a field of a plugin. We can apply behaviour on dropdown field not sure it works on XRay plugin field or not. 

Have you tried to apply Behaviour on this field similar to dropdown field ?

We dont have this plugin in our JIRA instance, so didn't get chance to apply Bheaviour on this field.

If you need a script similar to dropdown field i can share. or you can create new thread in Atlassian Community, might be anyone tested Behvaiour on XRay plugin field.

Thanks

Vikrant Yadav

 

Hello @Vikrant Yadav ,

 

yes, it is a special field part of the Xray plugin. The type of the field is also called "Test Repository Path". I am not sure what category it comes under.

21_7.png

 

Nevertheless, Could you please share the script for a dropdown field ?

I will see if i can relate that to this.

 

Thanks a lot for your assistance,

Venkat 

Vikrant Yadav Community Leader Jul 21, 2021

@Venkat_S  

https://www.idalko.com/use-behaviour-functionality-script-runner-show-hide-fields/

def dropDown = getFieldById("customfield_10500")
def conditionA = getFieldById("customfield_10501")
def conditionB = getFieldById("customfield_10502")
log.debug("dropdown value" + dropDown.getValue())

if (dropDown.getValue() == "a") {
conditionA.setHidden(false);
conditionB.setHidden(true);
} else {
conditionA.setHidden(true);
conditionB.setHidden(false);

}

 Thanks

@Vikrant Yadav 

My question is related to required field and it seems slightly related to this issue. Can you please help me on this

https://community.atlassian.com/t5/Jira-Software-questions/Fields-required-based-on-other-custom-field-values/qaq-p/2206598#M235497

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events