Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×I need a script that should check if the user in a particular group based component selected and then only assign
Lets say I have a components like A, B, C and JIRA groups like group1, group2 and group3 and if I select component A then the assignable user should be part of group1 or else it should throw a message saying like select a different user
same of component B and C
Hi @Sid
That should be fairly simple with scriptrunner behavior.
Start with something like this as the server-side script for the assignee field (just change values in componentMap).
import com.atlassian.jira.component.ComponentAccessor
def pcm = ComponentAccessor.projectComponentManager
def userUtil = ComponentAccessor.userUtil
def componentMap = [
'A':'group1',
'B':'group2',
'C':'group3'
]
def allowedGroups = componentMap.findAll{it.key in getFieldById('components').value*.name}.collect{it.value}
def fld = getFieldById(getFieldChanged())
fld.clearError()
if(allowedGroups){
if(! (fld.value in userUtil.getAllUsersInGroupNames(allowedGroups)) ){
fld.setError("This user is not in component-linked group(s): ${allowedGroups}. Select a different user.")
}
}
This assumes that if the component is not in the list of groups than all users are allowed.
Also, this will not block users from clicking "Assign to me" in the jira issue view and the action will complete successfully even if they are not in the allowed groups. But the next edit/transition will force them to change the assignee if that field is on the screen.
Thanks Peter, this gives really solves my issue
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am getting error no such property : name for class - here
def allowedGroups = componentMap.findAll{it.key in getFieldById('components').value*.name}.collect{it.value}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Are you getting this error when the script runs? Or just in the script editor?
If just in the script editor, it likely can be ignored. This is just because the object returned by getFieldById('components').value is not known by the code editor and it can't figure out if "name" is a correct attribute.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I get this on script editor, but seems this is not working as expected when I am assigning the users. (Both on create / edit screens)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Do you get any errors in the atlassian-jira.log file at the time of changing the assignee?
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.