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

ScriptRunner behaviour for hiding a field based on another fields value

Venkat_S July 21, 2021

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

Suggest an answer

Log in or Sign up to answer
3 votes
Answer accepted
Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 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)
}
Venkat_S July 21, 2021

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 21, 2021

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

Venkat_S July 21, 2021

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 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

 

Venkat_S July 21, 2021

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 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

siva December 1, 2022

@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

TAGS
AUG Leaders

Atlassian Community Events