Assignee behavior based on component selected

Sid
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 29, 2020

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 

1 answer

0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 30, 2020

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.

Sid
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 30, 2020

Thanks Peter, this gives really solves my issue

Sid
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 30, 2020

@Peter-Dave Sheehan , 

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}
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 31, 2020

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.

Sid
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 31, 2020

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)

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 31, 2020

Do you get any errors in the atlassian-jira.log file at the time of changing the assignee?

Suggest an answer

Log in or Sign up to answer