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

Ryan Davis January 22, 2021

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
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 24, 2021

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)
}
Ryan Davis January 25, 2021

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.

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 25, 2021

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

Ryan Davis January 25, 2021

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!

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 25, 2021

No problem! Glad to help!

0 votes
Ravi Sagar _Sparxsys_
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 22, 2021

Hi @Ryan Davis 

Do you mind sharing what you did so far?

Ravi

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events