As we know in Jira you can't have multiple contexts for a given Project for different Issue Types. I have the need to limit the selectable users for a User Select List based on Issue Type and/or Components.
Does anyone know a way to script in a Behaviors using Adaptavist's plugin Scriptrunner, to limit the selectable users based off of another field?
Ex: If Field1 has the value of "One" then only users in group "Group1" can be selected but if in Field1 that value is "Two" then only users in the Project Role "Role1" can be selected?
Thank you all in advance!
Hi @Joshua Kohn
For this requirement, you will need to configure two Server-Side Behaviour configurations,
The first will be for the Issue Type field, and the second will be for the Multi-User picker field.
Below is an example Behaviour code for the Issue Type:-
import com.atlassian.jira.user.ApplicationUser
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours behaviours
def issueType = getFieldById(fieldChanged)
def issueTypeValue = issueType.value as Integer
def sampleUserPicker = getFieldByName('Sample Multi User Picker')
def sampleUserPickerValue = sampleUserPicker?.value as List<ApplicationUser>
sampleUserPicker.clearError()
if (issueTypeValue == 10004 && sampleUserPickerValue.size() > 3) {
sampleUserPicker.setError('User Limit for Bug Type Has Exceeded')
} else if (issueTypeValue == 10001 && sampleUserPickerValue.size() > 4) {
sampleUserPicker.setError('User Limit for Story Type Has Exceeded')
} else if (issueTypeValue == 10002 && sampleUserPickerValue.size() > 4) {
sampleUserPicker.setError('User Limit for Task Type Has Exceeded')
}
Below is the example Behaviour code for the Multi-User picker field:-
import static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE
import com.atlassian.jira.user.ApplicationUser
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours behaviours
def issueType = getFieldById(ISSUE_TYPE)
def issueTypeValue = issueType.value as Integer
def sampleUserPicker = getFieldById(fieldChanged)
def sampleUserPickerValue = sampleUserPicker?.value as List<ApplicationUser>
sampleUserPicker.clearError()
if (issueTypeValue == 10004 && sampleUserPickerValue.size() > 3) {
sampleUserPicker.setError('User Limit for Bug Type Has Exceeded')
} else if (issueTypeValue == 10001 && sampleUserPickerValue.size() > 4) {
sampleUserPicker.setError('User Limit for Story Type Has Exceeded')
} else if (issueTypeValue == 10002 && sampleUserPickerValue.size() > 4) {
sampleUserPicker.setError('User Limit for Task Type Has Exceeded')
}
Please note that the sample codes provided are not 100% exact to your environment. Hence, you will need to make the required modifications.
The values that I have used for the Issue type, i.e. 10004, 10001, and 10002, are issue type Ids for the Bug, Story and Task types, respectively. This may not be the same in your environment. So you will need to get the correct ids for your environment.
Below is a screenshot of the Behaviour configuration:-
What this code will do is that if a particular issue type is selected, for example, Bug, and the number of users selected from the Multi-User picker exceeds the limit, in this example, 3 users, an error will appear on the dialog.
Only once the number of users is set to the limit permitted will the error message be removed, and can the issue be created or edited.
Below are a few test screenshots for your reference:-
1. First, when I try to create a Bug ticket and add more than 3 users to the Multi-User picker, the error message is displayed as expected
2. When I reduce the number of users to 3, the error message is removed as expected.
3. Similarly, if I try to add more than 4 users to the Multi-User picker when the Issue Type is set to Story, as expected, the error message is displayed
4. If I am only to set the number of users selected in the Multi-User Picker, the error message is removed as expected.
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
Thank you @Ram Kumar Aravindakshan _Adaptavist_ . While that was very informative, that was not what I was looking for.
My question is if there is a way to limit the users available for picking when browsing for users under a multi-user picker. Ideally from a group or a role.
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 @Joshua Kohn
To answer your question, no it is not doable because Jira controls it. This question has already been asked and answered previously in this Community Post.
This is why I have given you the alternative to using the validator to restrict the number of users.
You can, however, further enhance the code to include other conditions, e.g. restrict the user's Role or Group for the error message to work accordingly.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Joshua Kohn
I don't know how to do that with user picker field as it do not store users as option like select list fields.
What you can do is to control the user selected and set an error if it do not fullfil the required role/group but it's less user friendly as all users will be displayed to the user.
Another way to do that may be to use a scripted field (LDAP).
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Adding Scriptrunner expert @Ram Kumar Aravindakshan _Adaptavist_ .
Ram please help Joshua :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.