Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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
Ravi Sagar Community Leader Jan 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
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

479 views 5 19
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you