Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Assignee behavior based on component selected Edited

Sid Community Leader Jan 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

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 = [
def allowedGroups = componentMap.findAll{it.key in getFieldById('components').value*.name}.collect{it.value}

def fld = getFieldById(getFieldChanged())

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 Community Leader Jan 30, 2020

Thanks Peter, this gives really solves my issue

Sid Community Leader Jan 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}

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 Community Leader Jan 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)

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

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you