Forums

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

Hide a field with behaviour

Spruha Shah August 29, 2023

Hi, 

Can you help me write a script for behavior to only show the field on some projects and hide it for rest.

2 answers

0 votes
Hans Pesata
Contributor
August 29, 2023

HI!

To show/hide the field "Team" We did this:

- check the "Hidden" switch

- Add the script:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager


def formField = getFieldById("customfield_12601");    // Team Custom Field
def project = issueContext.projectObject.name


if (project == "Our Project")
{
  formField.setHidden(false)
}

Hope this helps!

regards,
Hans
Spruha Shah August 30, 2023

i am tyring to use this:

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager


def formField = getFieldById("customfield_12811");    // Production Deployment Required Field
def project = issueContext.projectObject.key


if (project != "EPDT","EPPAV","EPPC","EPPUN","EPPO","EPPP","EPPPL","EPPT","EPPU")
{
  formField.setHidden(true)
}
but the comma after "EPDT" in giving me an error.
Hans Pesata
Contributor
August 30, 2023

Hi!

Try this:

import java.util.*;


def list = ["EPDT","EPAV","EPPC","EPPUN","EPPO","EPPP","EPPL","EPPT","EPPU"]

if(list.indexOf(project) == -1)
{
  formField.setHidden(true)
}

Regards, Hans

0 votes
Laurie Sciutti
Community Champion
August 29, 2023

Hi @Spruha Shah ~ is there a reason you need a script rather than just a Field Config Scheme?

Spruha Shah August 29, 2023

We dont prefer changing our enterprise level templates for few projects that require this.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events