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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

Hi @venkataramanan_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

@venkataramanan_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

Hi @venkataramanan_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 

@venkataramanan_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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

⏰ Day in the life of a Jira Admin!

Hello Community! We thoroughly enjoyed this just-for-fun conversation in the Jira Admin Group about what it's like to be a Jira Admin. For #JiraJuly, our talented designers created these graphics t...

532 views 2 18
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you