Forums

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

Restricting issue types based on groups

Mary Mark September 14, 2023
Hi,
Wondering if someone knows what is wrong with the script below to restrict issue types based on groups.
I get the following error:
[Static type checking] - Cannot find matching method script16947277872381970688303#If(boolean, groovy.lang.Closure <java.lang.Boolean>). Please check if the declared type is correct and if the method exists.
Possible solutions: find(), any(), is(java.lang.Object), wait(), use(java.lang.Class, groovy.lang.Closure), dump()
=================================================
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.component.ComponentAccessor
import groovy.transform.BaseScript

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

@BaseScript FieldBehaviours fieldBehaviours

def groupManager = ComponentAccessor.groupManager
def allIssueTypes = ComponentAccessor.constantsManager.allIssueTypeObjects
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser

def issueTypeField = getFieldById(ISSUE_TYPE)

def remoteUserGroups = groupManager.getGroupsForUser(user)*.name
def availableIssueTypes = []

If ('Admins' in remoteUserGroups)
{
    availableIssueTypes.addAll(allIssueTypes.findAll { it.name in ["Admin Only Issue"] })
}
If ('Developers' in remoteUserGroups)
{
    availableIssueTypes.addAll(allIssueTypes.findAll { it.name in ["Developer Only Issue"] })
}

issueTypeField.setFieldOptions(availableIssueTypes)
====================================================
Thank you.

1 answer

0 votes
Kit Friend
Community Champion
September 14, 2023

What's the usecase you're trying to accomplish? Having the seperate issue types in seperate projects and restricting access that way would normally be more straightforward than using a script. 

Suggest an answer

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

Atlassian Community Events