Forums

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

Script Runner is not hiding issue type as per project role

Vikrant Yadav
Community Champion
April 6, 2020

Hi Friends,

 

I am trying to hide one Issue type via Script Runner Behaviours Plugin.  Same script i used for other project it's working, but on this project is not working. Please help

@Dominic Lagger @Nic Brough -Adaptavist- 

 

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 allIssueTypes = ComponentAccessor.constantsManager.allIssueTypeObjects

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

def projectManager = ComponentAccessor.projectManager
def availableIssueTypes = []

def allProjects = projectManager.getProjects()

def projectRoles = projectRoleManager.getProjectRoles(user, issueContext.projectObject)*.name


if(projectRoles==["Administrators"] || projectRoles== ["User"] || projectRoles== ["Developers"] || projectRoles==["Business Analysts"] || projectRoles==["Developers"]){
availableIssueTypes.addAll(allIssueTypes.findAll { (it.name != "Ad Hoc Request_OLD" ) && (it.name != "Ad Hoc Request MP" ) && (it.name != "Ad Hoc Request QOL" ) && (it.name != "Ad Hoc Tasks" ) })
}
else {
availableIssueTypes.addAll(allIssueTypes.findAll {(it.name != "Bug" ) && (it.name != "Task") })
}

issueTypeField.setFieldOptions(availableIssueTypes)

2 answers

0 votes
Kristian Walker _Adaptavist_
Community Champion
April 6, 2020

Hi Vikrant,

If the script is working for one project and not another project then this indicates that either the configuration for the behavior is invalid or that an error occurred.

In order to help yourself to troubleshoot the issue, I would advise that you look at the following items below.

1. Check the mapping for the behavior script as described here to ensure that is actually mapped to the project where it is not running on as the script will only run for projects that it is mapped for.

2. I would advise enabling logging for behaviors as mentioned here and then to re run the behavior and to re produce it not working and then to check the atlassian-jira.log file to see if this gives any errors related to the behaviors script.

I hope this information helps.

Regards,

Kristian

0 votes
Vikrant Yadav
Community Champion
April 6, 2020

Suggest an answer

Log in or Sign up to answer