ScriptRunner has an example of this only by Project Roles (https://docs.adaptavist.com/sr4js/6.33.0/features/behaviours/behaviours-examples/restricting-issue-types).
How exactly can I accomplish this with groups? Scenario: There are 3 issue types within a project: Task, Bugs, Incidents.
I want anyone who's in the "jira-users" group to be able to create only Task and Bugs
I want anyone who's int the "Incident Team" group to be able to create Task, Bugs, AND Incidents.
Thoughts?
For your requirement, you can reuse the code provided in the https://docs.adaptavist.com/sr4js/6.33.0/features/behaviours/behaviours-examples/restricting-issue-types page. But you will need to modify it slightly.
Below is a sample modified working code for your reference:-
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE
@BaseScript FieldBehaviours behaviours
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def groupManager = ComponentAccessor.groupManager
def issueTypeField = getFieldById(ISSUE_TYPE)
def availableIssueTypes = []
def developmentGroupUsers = groupManager.getUsersInGroup("Developers")
def adminGroupUsers = groupManager.getUsersInGroup("jira-administrators")
if (developmentGroupUsers.contains(loggedInUser)) {
availableIssueTypes.addAll(["Bug", "Story", "Epic"])
}
if (adminGroupUsers.contains(loggedInUser)) {
availableIssueTypes.addAll(["Task"])
}
issueTypeField.setFieldOptions(availableIssueTypes)
Please note, the working sample code provided is not 100% exact to your environment. Hence, you will need to make the required modifications.
Below is a print screen of the Behaviour configuration:-
In this scenario, you will need to use the Behaviour Initialiser instead of the Server-Side Behaviour.
And the groups that are going to be tested is the jira-administrators group and the Developers group.
To invoke the groups you want to use, you will need to use the groupManager and specify the group names you want to use, as shown below:-
def groupManager = ComponentAccessor.groupManager
...
...
def developmentGroupUsers = groupManager.getUsersInGroup("Developers")
def adminGroupUsers = groupManager.getUsersInGroup("jira-administrators")
Next, you will need to modify the if condition, i.e. instead of using the User Role, use the Group to set the condition as shown below:-
if (developmentGroupUsers.contains(loggedInUser)) {
availableIssueTypes.addAll(["Bug", "Story", "Epic"])
}
if (adminGroupUsers.contains(loggedInUser)) {
availableIssueTypes.addAll(["Task"])
}
Below are a few test print screens:-
1) When the Admin user who is in the jira-administrators group is used, and the issue is being created, the user is restricted to only the Task issue type as shown in the image below:-
2) When the user Ram who is in the Developers group is used, the user is restricted to the Bug, Story, Epic issue types as shown below:-
I hope this helps to answer your question. :)
Thank you and Kind Regards,
Ram
If this solution answers your question, please accept the solution.
Thank you and Kind Regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ram Kumar Aravindakshan _Adaptavist_ . Sorry I took a while, but your solution worked perfectly for my needs and I was able to modify it to fit my needs. Thank you so much very much for this help! I appreciate you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
On this note, I'd personally recommend what you have provided here to be added to the ScriptRunner's official KB since the official KB only tells you on how to do it by roles, but not by groups. Thank you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This only applies for jira server/data center. Is there a similar solution for JIra cloud + script runner?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here are instructions on how you would validate groups: https://library.adaptavist.com/entity/validate-the-user-group-of-the-assignee
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Fabian. Thank you for the insight. Is there a equivalent to use Behavior to also hide it? I think having a validator is a good idea as a safety net, but would prefer to just hide the Issue Type altogether by group from users who aren't supposed to see it.
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.