Hide Issue Types with ScriptRunner Behaviors (not working)

Büşra Saltık
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!
January 14, 2025

Hello,

I am using behaviors to hide specific issuetypes, i did the configuration (added a server side script to issuetype field in scriptrunner/behaviors) 1 week ago, it was working fine but now it doesnt work. 

What could be the reason?

I tried this script as well but it is switching it back to the ones that specified rather than hiding it.

Jira Data Center v9.12.7

2 answers

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 15, 2025

Hi @Büşra Saltık

Based on what condition do you intend to hide the Issue Type? Is it based on the User's Group or Role?

I have provided a solution for the former in this Community Post.

I'm looking forward to your feedback and clarification.

Thank you and Kind regards,
Ram

Büşra Saltık
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!
January 15, 2025

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

Thank you for your help.

I don't have a condition. I have several issuetypes in my scheme and i want to hide some of them so that the other projects using the same scheme wont be affected. I also did the project mapping in the behavior.

  • When i try your solution it doesnt allow me to pick issuetypes that i want to be hidden but it doesnt hide it. It just switches back to allowed issutype
import com.atlassian.jira.component.ComponentAccessor
def issueTypeField = getFieldById("issuetype")

def
 hiddenIssueTypes = [
    "Analysis", "Epic"

]

def issueTypes = ComponentAccessor.getConstantsManager().getAllIssueTypeObjects()
def visibleIssueTypes = issueTypes.findAll { it.name !in hiddenIssueTypes }

issueTypeField.setFieldOptions(visibleIssueTypes.collectEntries { [(it.id): it.name] })
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 15, 2025

Hi @Büşra Saltık

Please share a screenshot of your Behaviour configuration. I need this to check how you are associating your Behaviour configuration with the Projects and rerun the test in my environment.

Thank you and Kind regards,
Ram

 

0 votes
Rilwan Ahmed
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 14, 2025

Hi @Büşra Saltık ,

Welcome to the community !!

You have shared the link for plugin version 6.33.0. Script runner 6.33.0 is not compatible with Jira datacenter 9.12.7.
image.png

 

Script runner 8.22.0 and above is only compatible with Jira 9.12.17. 

As you said, "1 week ago, it was working fine", was there any upgrades to plugin or Jira version in recent days ?

You can find the updated way to restrict Issue type here for the latest plugin version: https://docs.adaptavist.com/sr4js/9.6.0/features/behaviours/behaviours-examples/restricting-issue-types

 

Büşra Saltık
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!
January 14, 2025

Hi @Rilwan Ahmed

Thank you for your reply.

We are using Scriptrunner version 8.30.0

We renew the service management licence yesterday. Could that be the reason? All the other behaviors are working fine, only the one for issuetype field is not working.

Rilwan Ahmed
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 14, 2025

Hi @Büşra Saltık 
Did you check the license for plugin ? Is it expired or not. Same number of user license as JSM ?

Meantime try to recreate it using the steps given in https://docs.adaptavist.com/sr4js/8.30.0/features/behaviours/behaviours-examples/restricting-issue-types

I suggest first you try in Test environment. If test environment does not exist, try only for test project. 

Büşra Saltık
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!
January 14, 2025

Hi @Rilwan Ahmed

Everything is valid. When i apply the script given in the link;

When I select the issue type that should be hidden, it converts it into a visible issue type and allows me to select it, but it doesn't hide the other options

Thank you for your help!

Rilwan Ahmed
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 14, 2025

Can you please share your script here. 

Also please check for roles mentioned in the script. Are you part of it not, if the roles are available in your project or not etc. 

Büşra Saltık
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!
January 15, 2025
Yes i am the administrator, i have the needed permissions. 
Following script is the one that was working 1 week ago, 

import com.atlassian.jira.component.ComponentAccessor

def issueTypeField = getFieldById("issuetype")
def hiddenIssueTypes = [
    "Analysis", "Epic"
]

def issueTypes = ComponentAccessor.getConstantsManager().getAllIssueTypeObjects()
def visibleIssueTypes = issueTypes.findAll { it.name !in hiddenIssueTypes }

issueTypeField.setFieldOptions(visibleIssueTypes.collectEntries { [(it.id): it.name] })
Rilwan Ahmed
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 15, 2025

Hi @Büşra Saltık ,

Go to Script runner --> Behaviors --> Create Behavior --> Give a name and click on Create Mapping

Here select Project name and All issue types. 

image.png

 

Scroll down and add below script (modify the Issue type names and Roles as per your project and based on who should see what issue types)

 

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

import static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE

def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)

def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def issueTypeField = getFieldById(ISSUE_TYPE)

def userRoles = projectRoleManager.getProjectRoles(user, issueContext.projectObject)*.name
def availableIssueTypes = []

//allow only users in 'Administrators' project role to get Query and 'General Request' issue types as dropdown
if ("Administrators" in userRoles) {
availableIssueTypes.addAll(["Query", "General Request"])
}

//allow only users in 'Developers' project role to get "Task" issue types as dropdown
if ("Developers" in userRoles) {
availableIssueTypes.addAll(["Task"])
}

issueTypeField.setFieldOptions(availableIssueTypes)

 

 

Büşra Saltık
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!
January 15, 2025

Yes, i applied this one but still 

When I select the issue type that should be hidden, it converts it into a visible issue type and allows me to select it, but it doesn't hide the other options.

 

I believe there is another issue

Rilwan Ahmed
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 15, 2025

@Ram Kumar Aravindakshan _Adaptavist_ is from Script runner plugin team. He can surely help/guide you here better. 

Suggest an answer

Log in or Sign up to answer