Forums

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

How to use Groovy to control the fields show or hide?

yundong.li
Contributor
March 9, 2022

I have three fields, office, department, username, they are all hidden by default.

when I click  To_do step, then display username, office, department;
and In the next_1 step, display username, office, hide department;
And in next_2, display  username, department, hide office;
When done, all three fields are displayed.

How could I use Groovy to do that ,have someone give an example?

thanks.

1 answer

0 votes
Fabio Racobaldo _Herzum_
Community Champion
March 9, 2022

Hi @yundong.li ,

in order to put in place that, you should setup a Behaviour provided by Script Runner.

https://scriptrunner.adaptavist.com/latest/jira/behaviours-overview.html

Here a tutorial https://scriptrunner.adaptavist.com/latest/jira/tutorials/behaviours-tutorial.html

in order to show/hide a specific field you should use setHidden method based on your conditions :

def myFirstField = getFieldByName("custom_field_name");

myFirstField.setHidden(false/true);

Hope this helps,

Fabio

yundong.li
Contributor
March 9, 2022

hi @Fabio Racobaldo _Herzum_ 

Thanks for your help.

Yes , I do it like this. but it cannot do what I need.

I need to get the status value of the workflow node, 

and then control the display of the field according to the status value.

 

Do you know how to get the state value of the node ?

 

Sorry , I am not very good at Scriptrunner, Can you help to give an example?

Fabio Racobaldo _Herzum_
Community Champion
March 9, 2022

Hi @yundong.li ,

here an example that should work on your scenario :

import com.atlassian.jira.issue.Issue;

Issue issue = getUnderlyingIssue();

def field1 = getFieldByName("CUSTOM_FIELD_1_NAME_HERE");
def field2 = getFieldByName("CUSTOM_FIELD_2_NAME_HERE");
def field3 = getFieldByName("CUSTOM_FIELD_3_NAME_HERE");

field1.setHidden(true);
field2.setHidden(true);
field3.setHidden(true);

String statusName = issue.getStatusObject().getName();

if("YOUR_STATUS_NAME_HERE".equalsIgnoreCase(statusName)){
field1.setHidden(false);
}

Obviously you need to adapt this behaviour at your requirments.

Fabio

Suggest an answer

Log in or Sign up to answer