Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

How to hide a field based on Issue Security Level (ScriptRunner)?

Hello all,

I am currently trying to find out how to use Scriptrunner's Behaviors functionality to hide a custom field (multi user select field) based on the Issue Security Level of the issue. In an ideal world, I would like to have the field "Watchers" be hidden (creating/editing/viewing) when the Security Level name contains/starts with "Confidential".

Is there an easy way to do this in behaviors? I have tried many attempts with different answers from the past questions on this forum, but none seem to work. I think the main issue is that the Security Level field acts differently from standard custom fields (or at least I think it does). I am also open to hard coding the level IDs as the condition, but preferably if the string match method could work that would be ideal.

Any help would be greatly appreciated! Thank you!

2 answers

1 accepted

1 vote
Answer accepted

You can't hide a custom field in view screen with Behaviour: limitations (screen)community answer.

Also, you "Watchers" field is not available in create and edit screen. It is not exactly a field.

Having said that, you can hide the other field in create and edit screen with:

import com.atlassian.jira.component.ComponentAccessor

def issueSecurityLevelManager = ComponentAccessor.getIssueSecurityLevelManager()
def securityLevelName = issueSecurityLevelManager.getIssueSecurityName(getFieldById(getFieldChanged()).getValue() as Long)

if (securityLevelName?.contains("Confidential")) {
getFieldByName("Your Field").setHidden(true)
} else {
getFieldByName("Your Field").setHidden(false)

Should I be putting this code in the Initialiser or on the field? For some reason either method doesn't work. The Watchers field is a custom multi user select field, not the standard Watchers field from Jira. I have renamed it to Procurement Watchers to avoid confusion. I would only need to hide it in create or edit anyways, if the field was empty it would not show in the View screen.

You need to attach it to the issue "Security Level" field. I have tested it in my local machine, it works fine.

Okay my issue was that I was attaching it to the Procurement Watchers field, your method is exactly what I was looking for. Thank you very much!

No problem! Glad to help!

0 votes

Hi @Ryan Davis 

Do you mind sharing what you did so far?


Suggest an answer

Log in or Sign up to answer

Atlassian Community Events