Hi,
We are using many issue types, but want role "service desk team" to view and create issue type "Incidents" only. The rest of the issue types should not be available, either to view in the create menu or anywhere else. It will just cause confusion.
I have tried the following script from the scriptrunner library, but get an error. Any ideas?
Hi Hana,
This worked.
Now users in a given role have the issue types available to them restricted accordingly.
It was also very simple to implement.
Thank you
Mark
Hi @Mark Fallaize,
welcome to the Atlassian community!
Instead of ... (three dots) there should be listed some classes, which needs to be imported.
One of them would probablby be:
import com.atlassian.jira.component.ComponentAccessor
Also it looks like variable constantsManager is not defined, so you should add after line 5 (definition of projectRoleManager) line
def constantsManager = ComponentAccessor.getConstantsManager()
Would you please provide me url to the ScriptRunner Library, where you get the script?
Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Hana,
Thank you for your quick reply, I just returned back to office.
I used: https://scriptrunner.adaptavist.com/latest/jira/recipes/behaviours/restricting-issue-types.html
With your additions, I get the following error message:
The script could not be compiled: The script could not be compiled: <pre>org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script91.groovy: 2: unexpected token: com @ line 2, column 8. static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE ^ 1 error </pre>.
Sorry but I am new to this code, what might be the issue?
Thanks
Mark
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Mark Fallaize,
sorry for the late response.
Please add the word "import" before the word "static" on the second line.
I tried to write the script for you - unfortunately I'm not able to try it right now because of the problems with my test instance, but I believe it could work.
Basically the script just checks, if logged in user has project role Service Desk Team. If so, then the type field is limited to only Incident and set to read only. There are no changes for other users without role Service Desk Team.
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 remoteUsersRoles = projectRoleManager.getProjectRoles(user, issueContext.projectObject)*.name
if ("Service Desk Team" in remoteUsersRoles) {
def availableIssueTypes = allIssueTypes.findAll { it.name in ["Incident"] }
issueTypeField.setFieldOptions(availableIssueTypes)
issueTypeField.setReadOnly(true)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Hana,
Thank you for trying. Unfortunately we get the following error:
groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getFieldById() is applicable for argument types: (java.lang.String) values: [issuetype] at Script94.run(Script94.groovy:10)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Mark Fallaize,
to be honest - this is very strange. Would you please write me information, where exactly in your system do you have this code? Is it really saved as a Behaviours script? Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Hana,
Thank you for your reply.
The above errors were highlighted in the Scriptrunner console. I also tried it in the Script Editor with the same result.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Mark Fallaize ,
thank you, now I understand, where the problem is. This script (and also the original one from the library) must be used in Behaviour, it won't work in "standard" ScriptRunner.
Please follow these instructions:
Your settings should look something like this:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Anyone know how to get a 'not in' working? All I'm trying to do is to say, if the user is NOT IN "Users" role, basically the rest of the company, then restrict the issue type to Service Request, I'm using the template on the Behaviours site, but when I put in not in or != it doesnt work.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
import
static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE
// if the current user is in the Users role only, set the issue type to "Query", and lock it
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def remoteUsersRoles = projectRoleManager.getProjectRoles(user, issueContext.projectObject)*.name
if (remoteUsersRoles != ["Users"]) {
def constantsManager = ComponentAccessor.getConstantsManager()
def queryIssueType = constantsManager.getAllIssueTypeObjects().find { it.name == "Service Request" }
getFieldById(ISSUE_TYPE).with {
setFormValue(queryIssueType.id)
setReadOnly(true)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.