Hide Issue Types with ScriptRunner Behaviors (not working)

Büşra Saltık 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

Suggest an answer

Log in or Sign up to answer
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 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

 

Büşra Saltık January 15, 2025

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

Thank you for your help!

It turns out that the issue is specific to my user account; other users are seeing it as it is supposed to be.

Interestingly, when I use "Switch User" and view it from someone else's account, I see all the issue types. However, when I ask the actual user, they confirm that they do not see all the issue types.

I am still curious why that is happening.

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

As requested in my previous comment, please share a screenshot of your Behaviour configuration. It will help me better understand the issue you are facing.

You mentioned in your last comment:-

It turns out that the issue is specific to my user account; other users are seeing it as it is supposed to be.

What differentiates you from the other users for whom the Behaviour works? Are you in different groups or roles?

Are there any conditions set in the Behaviour configuration to restrict the Behaviour to specific groups?

I suggest trying the steps below:-

  1. Temporarily disable all your Behaviour configurations
  2. Create a new Behaviour configuration and set it to only one Project
  3. Ensure that you only use the Behaviour Initaliser and no other fields and rerun the test.

I am looking forward to your feedback.

Thank you and Kind regards,
Ram

 

Büşra Saltık January 15, 2025

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

I am one of the Jira admins in our instance. While the other admin was seeing it the right way, It doesnt work on my user. We have the same permissions both in jira and project itself.

image (19).pngimage.jpg

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 17, 2025

Hi @Büşra Saltık

Thank you for providing the screenshot.

I will test this in my environment and get back to you once I have an update.

Thank you and Kind regards,
Ram

Like Büşra Saltık likes this
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 17, 2025

Hi @Büşra Saltık

I ran a basic test in my environment and I am not facing any issues.

I can confirm that the approach you are taking is incorrect based on the screenshot of the behaviour configuration you shared.

Instead of using a Server-Side Behaviour, you will need to use the Behaviour Initialiser to set the default options on the Issue Type since you are not depending on a field to update before triggering the Behaviour.

Below is the sample working code that I have tested with:-

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours
def issueType = getFieldById('issuetype')
issueType.setFieldOptions(['Bug', 'Story'])

Please note that the sample working code above is not 100% exact to your environment. Hence, you must make the required modifications.

Below is a screenshot of the Behaviour configuration:-

behaviour_config.png

 

As shown in the screenshot above, the Behaviour configuration is mapped to the project MOCK. So if I try to create an issue in the Mock Project, as expected, I am only able to get 2 options from the Issue Type field as shown in the screenshot below:-

test1.png

With the test above, I have logged in with my own account as the Jira Administrator.

It works the same even if I test it as a non Jira Admin user.

If the Behaviour is disabled, all the Issue Types are displayed as expected as shown in the screenshot below:-

test2.png

Also as I mentioned in my previous comment:-

I suggest trying the steps below:-

  1. Temporarily disable all your Behaviour configurations
  2. Create a new Behaviour configuration and set it to only one Project
  3. Ensure that you only use the Behaviour Initaliser and no other fields and rerun the test.

Please try the step above, because when I test in my environment, I have only one Behaviour enabled and I'm not having any problems.

I hope this helps to solve your question. :)

Thank you and Kind regards,
Ram

Büşra Saltık January 17, 2025

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

Thank you so much for your help!

I tried your sugggestions and script as well but unfortunately it doesn't work on my user (i get the same result with my solution).

It works on other users (when i switch user in their account, I see the options that I see in my account).

I give up at this point, at least it works on their account :)

Thank you for your time and effort,

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 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 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 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 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. 

Like Büşra Saltık likes this
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

@Büşra Saltık 

Please check if there are any other behavior's conflicting or overriding with this script. 

Like Büşra Saltık likes this
TAGS
AUG Leaders

Atlassian Community Events