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

IF/Else statement in post function does not work Edited

I'm trying to set my assignee based on components and a select custom field value. For some reason, it is not picking up the correct user. When I choose component "Hardware" and Location "Rotterdam", it would be username1. When I choose component "Hardware" and Location "Utrecht", it would also be username1. Same goes with the last option. I'm not too sure why the if-else statement is behaving this way. Any help? Any ideas?


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.customfields.manager.OptionsManager

final String user1 = 'username1'
final String user2 = 'username2'
final String user3 = 'username3'

def one = ComponentAccessor.getUserManager().getUserByName(user1)
def two = ComponentAccessor.getUserManager().getUserByName(user2)
def three= ComponentAccessor.getUserManager().getUserByName(user3)

def cf = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).find { == 'Location'}
def cfConfig = cf.getRelevantConfig(issue)

// select custom field values

def utrecht = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find { it.toString() == 'Utrecht' }
def rotterdam = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find { it.toString() == 'Rotterdam' }
def copenhagen = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find { it.toString() == 'Copenhagen' }


def isHardwareSelected = issue.components*.name.contains('Hardware')

if(rotterdam && isHardwareSelected){
issue.setAssignee(one )

}else if(utrecht && isHardwareSelected){

}else if(copenhagen&& isHardwareSelected){


1 answer

1 accepted

1 vote
Answer accepted
Leo Community Leader Feb 17, 2021

Hi @Filzah Aziz 

I don't find any issue with your script except the method you are trying to fetch selected custom field(Location) option.

If I'm not wrong your script choose the 1st one always when hardware is selected irrespective of location, if so that is expected

def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName("Location")[0]
String val = issue.getCustomFieldValue(cfSelect) as String

if((val == "Utrecht")&& isHardwareSelected){
issue.setAssignee(one )

}else if((val == "Rotterdam") && isHardwareSelected){

}else if((val== "Copenhagen")&& isHardwareSelected){


Best Regards,


Yes indeed! Thanks for that- i've added your bit to my script :) 

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