How to 'lock' a field during a Closed status (not during a transition)

Lara Arthur
Contributor
January 19, 2021

Hello Atlassian users,

I have a custom field that should be 'locked' while in a Closed status. So after the issue has transitioned to Closed, the field should only be viewable, not writeable. 

I have tried adding a Behaviour using ScriptRunner, but I can only make the field un-editable during a workflow transition...not during the workflow Closed status itself. 

I have looked at adding a listener...but unsure of what the code should look like and if this will do want I envision...or the same thing as the Behaviour.  (I do not want to only have the custom field on the view screens either).

End result should render the custom field read only while the issue is in the Closed status. Once the issue is re-opened, it can be writeable again.

Any assistance/thoughts are appreciated. Thanks--Lara

3 answers

1 accepted

0 votes
Answer accepted
Max Lim _Adaptavist_
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.
January 20, 2021

Are you saying you want restrict a field to be read-only when the status is "Closed"?

 

You can try to put this snippet in a Behaviour's Initialiser:

def status = underlyingIssue.getStatus().getSimpleStatus().getName()

if (status == "Closed") {
getFieldByName("Your Field Name").setReadOnly(true)
}
Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 20, 2021

@Max Lim _Adaptavist_ what about inline edit? I guess, behaviours solution is acceptable only when Field is not placed on Edit screen. Am I right?

I guess we need more information to provide better solution :)

Max Lim _Adaptavist_
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.
January 20, 2021

I tested it, this will work even when you are just viewing the issue and inline edit.

Try it yourself. 👍🏻 Just remember to refresh your issue viewing tab after saving the behaviour.

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 20, 2021

Great, I had no idea that behaviours works on view screen. I always set it up on transition screens. Thank you for clarification :).

Lara Arthur
Contributor
January 20, 2021

@Max Lim _Adaptavist_ I'll give it a try, thanks!

Lara Arthur
Contributor
January 20, 2021

@Max Lim _Adaptavist_ Thank you! Works like a charm. Appreciate the assistance :-).

0 votes
Matt Doar
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 19, 2021

If you have ScriptRunner then a Behaviour is the way. If not, then jira.issue.editable property in https://confluence.atlassian.com/adminjiraserver/workflow-properties-938847526.html for Server/Data Center

Lara Arthur
Contributor
January 20, 2021

@Matt Doar Behaviour seems to only allow it during transition...I want to be able to edit on transition to Closed...just not during the issue being in closed status.

0 votes
Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 19, 2021

Hi @Lara Arthur what type of custom field is it? Is it built-in field? Do you need to edit other fields in Closed status?

Lara Arthur
Contributor
January 20, 2021

Hi @Martin Bayer _MoroSystems_ s_r_o__ . Custom created field - single select list. Yes, all other fields can be editable.

We capture and report on a Bug Category field in our Bug issue type. Right now if it is in Closed status, some one can actually change it to 'None', but we want to freeze the field on Closed in order to always query on Closed and have a valid selection in the field... if that makes sense.

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 20, 2021

OK, if it is custom created field, it is quite easy to adjust the source code so it is not editable when issue's status is "X". But I guess behaviours is enough for you :).

If you would like to check the possibility which does not include 3rd party apps, just let me know.

Suggest an answer

Log in or Sign up to answer