Forums

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

Jira script/listener/behavior - how to control hiding/unhiding a custom field having a value?

sujoychakraborty93 July 28, 2021

Jira script/listener/behavior - how to control hiding/unhiding a custom field having a value? For e.g. sometimes, I want to hide it even if it has a value in it and sometimes I want to show the field based on some condition. 

Example: Say I have two single select fields - Field1 having  options as O1, O2. If I select O1, then the other field Field2 should appear. Field2 is also a single select field having options as Op1, Op2, Op3. Lets say I select Op2. 

Now if I change Field1 to O2, Field2 should disappear from the edit and view screen. '

I tried using Behavior. But the problem I am facing - because Field2 has a value in it, on View screen, the field appears. 

What I want is - retain the value of Field2 and still hide it. 

Said that, I dont want to remove Field2 permanently from View screen because I want to see it (with its old value) when option O1 is selected on Field1. 

So may be if there is some script that I can use that will allow me to control adding/removing a field from a screen, it may work. 

Appreciate any solution. 

N.B. - i have a workaround but would like to know if there is any direct solution to this.
Workaround:- create a new field (Field2-backup) and dont add that to any screen. Then use it to store the old value of Field2 and then remove the value from Field2. Now Field2 will not appear on View screen as iot does not have a value. And in future when O1 is selected, pull the value from Field2-backup and populate it in Field2. 

1 answer

0 votes
Radek Dostál
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 28, 2021

Behaviours don't work with the View screen. The most they can do is that when you try to modify the field values, it will take you to the edit screen and apply whatever conditions you set up (as opposed to changing the value on the view screen itself), but, you cannot hide a field from the view screen - not with a behaviour.

There's not really a way to hide a field from issue view, if you have that field on the view screen in the first place and it has a value - then it's simply going to be visible. I can understand that Jira nowadays has very different use cases, but in general, why would you want to hide the field, if it has a value? Is it some form of confidentiality issue, e.g. something the reporter should not be aware of?

Because one way or another, you cannot ever fully IOO% hide something from the user. Whatever changes you do during the issue's lifecycle, it will be in issue history.

You could try to do your own js/css to hide the cf values from view, but, that's not a secure way to do it anyway - either, there would be a delay before JS is applied, or, the user could manipulate the DOM to get the field value if you simply tried to hide it. Yes it would cover most cases and most non-technical users, but the point is you cannot really achieve absolute field invisibility. Likewise, you would see the field value with a simple REST API endpoint.

I believe I came across a plugin in the past which sorted field security in the way you describe it, but I can't remember the name right now. At minimum I'm quite confident that you will not be able to use scriptrunner to hide the field from the view - it doesn't work with the view screen.

Suggest an answer

Log in or Sign up to answer