Forums

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

I am writing a code to hide the issue types and the component's for the same project its not working

Saudamini Deshmukh
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 28, 2025

 

Subject: Help Needed – Component and Issue Type Behavior Scripts Not Working Together

Hello Team,

I've implemented two behavior scripts in Jira – one for setting components and the other for restricting issue types – scoped to the ABC project and all issue types.


Script 1: Components Behavior

This script filters and sets allowed components from a predefined list (["a","b","c","d"]) for the Components field.

 

import com.atlassian.jira.component.ComponentAccessor
def allowedComponentNames = ["a","b","c","d"]
def project = issueContext.projectObject
def projectComponentManager = ComponentAccessor.projectComponentManager def allComponents = projectComponentManager.findAllForProject(project.id)
def allowedComponents = allComponents.findAll { it.name in allowedComponentNames } log.debug("Allowed Components: ${allowedComponents*.name}")
def componentsField = getFieldById("components") componentsField.setFormValue([]) // Clear any pre-selected values componentsField.setFormValue(allowedComponents.collect { it.id.toString() })

 

 

Script 2: Issue Type Behavior

This script limits visible issue types based on user group membership. Users in the Mainframe Technical Support group also see the "Infrastructure" issue type.

 

groovy
CopyEdit
import com.atlassian.jira.component.ComponentAccessor
import static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE
def issueTypeField = getFieldById(ISSUE_TYPE) def allowedIssueTypeNames = [ "Break/Fix", "Enhancement", "New Feature", "Question", "Security", "System Performance" ]
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser def groupManager = ComponentAccessor.groupManager
def isMainframeSupport = groupManager.isUserInGroup(user, "Mainframe Technical Support")
if (isMainframeSupport) {     allowedIssueTypeNames += "Infrastructure"     log.warn(allowedIssueTypeNames) }
def project = issueContext.projectObject def projectIssueTypes = project.issueTypes
def visibleIssueTypes = projectIssueTypes.findAll { it.name in allowedIssueTypeNames } issueTypeField.setFieldOptions(visibleIssueTypes)
 

Problem:

  • Individually, each script works as expected.

  • Together, only the script placed last (or active) seems to take effect.

  • I have also tried combining them into a single initializer, but the issue persists.


Request:

Could you help me identify why both behavior scripts aren’t working simultaneously? Is there a known limitation in the Jira Behaviors plugin regarding multiple field-specific scripts or combined logic execution?

Any guidance or workaround would be appreciated.

1 answer

0 votes
Marc - Devoteam
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.
May 28, 2025

Hi @Saudamini Deshmukh 

Welcome to the community.

Best is to contact Adapatavist (the vendor and developer or Scriptrunner app).

I do think, you can only have one behaviour per issue type.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events